Dear Community,
In this tutorial I provide you with the code to make materials on objects in your game world respond to the velocity of the player pawn / Kactor. See video below for some entertaining examples!
You can use the essence of what I am showing you here to control many aspects of your materials directly with unrealscript to cause effects like
1. Materials change color as the percent of enemies left alive changes
2. A 3d material indicator reports the player health or ammo levels by changing color or switching between several different textures or brightness levels
3. walls “light up” by changing their brightness levels when the player unit touches them, etc!
The way this is done is through what are called Material Instances
~~~
How the Whole Screen Rainbow Effect Works
Whole Screen Effects, Material Effects in Post Process Chain
~~~
How to Make Materials Respond to Player Velocity
Step 1: You must create your Material and convert some of its values into parameters.
Here's a great tutorial on the basics of this process.
~~~
Material That Changes Color In Response to Player Unit Velocity
Here's the entire material code for the color changing material from my video:
Sine period = 0.3
Fresnel power = 2
Lerp = LinearInterpolate

~~~
Unreal Script Code
Step 2: Here's the code you need to add to your player pawn / kactor or other creature class so that the velocity of your actor affects the material's color.
~~~
Interpolate Between Two Textures Based On Normalized Player Velocity
Controlling the Speed of the Lightning Effect on the Material
Motion_4wayChaos is a Material function, use the lower search bar
Same for the VectorToRadialValue function
Please note that the 4wayChaos will ONLY take in a TextureObject, took me awhile to understand this.
I am using my own custom black/white mask of size 1024x1024 as the texture, you can easily make your own or find a mask in the UDK.

Converting Vector To Angle Via Material Function
Notice how the Lerp / LinearInterpolator has A and B as a Red and Black, and a Pink and Dark Blue texture respectively.
The alpha channel of the Lerp is used to decide how much of A and B to show.
The Velocity function is converting the parameterized input into an angle for us, and this is the alpha of the Lerp.
Notice the Velocity function can also retrieve the distance value of the input parameter.

~~~
How to Parameterize The Sine Function's Period
How to control / expose the material sine function period value with unrealscript code
This took me awhile to figure out! I hope you can make use of this in your own material instance adventures!

~~~
Summary
Use the basic process I am showing you here to cause your game world to come to life in response to player actions or other aspects of your game's gameplay!
So many possibilities!
Enjoy!

Rama
In this tutorial I provide you with the code to make materials on objects in your game world respond to the velocity of the player pawn / Kactor. See video below for some entertaining examples!
You can use the essence of what I am showing you here to control many aspects of your materials directly with unrealscript to cause effects like
1. Materials change color as the percent of enemies left alive changes
2. A 3d material indicator reports the player health or ammo levels by changing color or switching between several different textures or brightness levels
3. walls “light up” by changing their brightness levels when the player unit touches them, etc!
The way this is done is through what are called Material Instances
~~~
How the Whole Screen Rainbow Effect Works
Whole Screen Effects, Material Effects in Post Process Chain
~~~
How to Make Materials Respond to Player Velocity
Step 1: You must create your Material and convert some of its values into parameters.
Here's a great tutorial on the basics of this process.
~~~
Material That Changes Color In Response to Player Unit Velocity
Here's the entire material code for the color changing material from my video:
Sine period = 0.3
Fresnel power = 2
Lerp = LinearInterpolate

~~~
Unreal Script Code
Step 2: Here's the code you need to add to your player pawn / kactor or other creature class so that the velocity of your actor affects the material's color.
Code:
//Put this code in your pawn or KActor //or other PLayer OBJ class //Or you could put this in the enemy //pawn / creature class if you want //to have the world's materials //respond to their velocity. //Velocity Aware Materials var MaterialInstance velocityColorResponder; Simulated Event PostBeginPlay() { super.postbeginplay(); //set gameinfo, this is my game info //enables me to access the instance of this class //after game starts CustomGameInfo(WorldInfo.Game).playerOBJ = Self; //======== Velocity Sensitive Materials ============================ velocityColorResponder = new Class'MaterialInstanceConstant'; velocityColorResponder.SetParent( Material'YourPackage.Materials.VelocityColorResponder'); } Simulated Function tick( Float DeltaTime ) { local vector unitVelocity; local vector unitVelocityNormalized; local LinearColor unitVelocityColor; //very important line super.tick(deltatime); //~~~~~ //gets velocity of this class instance (Self) unitVelocity = StaticMeshComponent.GetRootBodyInstance().GetUnrealWorldVelocity(); //normalized velocity //remove unitVelocity var for efficiency //kept for clarity unitVelocityNormalized = Normal(unitVelocity); //Velocity Normalized or else the colors get waay //too bright (my player unit can have vel. of 1100+ unitVelocityColor.R = unitVelocityNormalized.x; unitVelocityColor.G = unitVelocityNormalized.y; unitVelocityColor.B = unitVelocityNormalized.z; unitVelocityColor.A = 1; //you could use alpha channel to store //additional useful info for your material instance //color responder velocityColorResponder.SetVectorParameterValue('Color', unitVelocityColor); }
Interpolate Between Two Textures Based On Normalized Player Velocity
Controlling the Speed of the Lightning Effect on the Material
Motion_4wayChaos is a Material function, use the lower search bar
Same for the VectorToRadialValue function
Please note that the 4wayChaos will ONLY take in a TextureObject, took me awhile to understand this.
I am using my own custom black/white mask of size 1024x1024 as the texture, you can easily make your own or find a mask in the UDK.

Converting Vector To Angle Via Material Function
Notice how the Lerp / LinearInterpolator has A and B as a Red and Black, and a Pink and Dark Blue texture respectively.
The alpha channel of the Lerp is used to decide how much of A and B to show.
The Velocity function is converting the parameterized input into an angle for us, and this is the alpha of the Lerp.
Notice the Velocity function can also retrieve the distance value of the input parameter.

Code:
//Velocity Aware Materials var MaterialInstance velocityResponder; Simulated Event PostBeginPlay() { super.postbeginplay(); //set gameinfo, this is my game info //enables me to access the instance of this class //after game starts CustomGameInfo(WorldInfo.Game).playerOBJ = Self; //======== Velocity Sensitive Materials ============================ velocityResponder = new Class'MaterialInstanceConstant'; velocityResponder.SetParent( Material'YourPackage.Materials.VelocityResponder'); velocityResponder.SetScalarParameterValue('Speed', 1); } Simulated Function tick( Float DeltaTime ) { local vector unitVelocity; local vector unitVelocityNormalized; local LinearColor unitVelocityColor; //very important line super.tick(deltatime); //~~~~~ //gets velocity of this class instance (Self) unitVelocity = StaticMeshComponent.GetRootBodyInstance().GetUnrealWorldVelocity(); //normalized velocity unitVelocityNormalized = Normal(unitVelocity); //Velocity Normalized or else the colors get waay //too bright (my player unit can have vel. of 1100+ unitVelocityColor.R = unitVelocityNormalized.x; unitVelocityColor.G = unitVelocityNormalized.y; unitVelocityColor.B = unitVelocityNormalized.z; unitVelocityColor.A = 1; //you could use alpha channel to store //additional useful info for your material instance //velocity and direction responder VelocityResponder.SetVectorParameterValue('Velocity', unitVelocityColor ); velocityResponder.SetScalarParameterValue('Speed', vsize(unitVelocity) / 700); }
How to Parameterize The Sine Function's Period
How to control / expose the material sine function period value with unrealscript code
This took me awhile to figure out! I hope you can make use of this in your own material instance adventures!

~~~
Summary
Use the basic process I am showing you here to cause your game world to come to life in response to player actions or other aspects of your game's gameplay!
So many possibilities!
Enjoy!

Rama
Comment