Game Development Reference
In-Depth Information
Listing 3.6 Code to Scroll a Texture over the Surface of a Mesh
var uvSpeed: Vector2 = new Vector2( 0.0f, 1.0f );
var uvOffset: Vector2 =;
function LateUpdate()
uvOffset + = ( uvSpeed * Time.deltaTime );
renderer.materials[0].SetTextureOffset("_MainTex", uvOffset);
Step 18. To move the character itself with the arrow keys, create a new
JavaScript called walk.js , add the code in Listing 3.7 , and attach it to the
character's plane.
Listing 3.7 Adding Forward, Backward and Idle Animations
var speed:float = 0.5;
function Update ()
this.transform.position.x + = speed;
this.transform.position.x - = speed;
Step 19. Play. The arrow keys will move the sprite back and forth in front
of the background. Remove the scrolling script from the background to
get a better idea of how the character is moving.
Step 20. With the walking speed set to 0.5 the character appears to slide
across the ground. This is a common error made by beginner animators
when creating walk cycles and placing the character into an environment
whether it is in 2D or 3D. The idea is to get the walk cycle speed to match
the motion speed so that each foot appears to be planted into the ground.
For this character, a speed of about 0.06 is a close match for a frame rate of
15. Try this out.
Search Nedrilad ::

Custom Search