Game Development Reference
In-Depth Information
Listing 3.10 Adding Forward, Backward and Idle Animations.
private var speed = 0.01;
function Awake()
this.animation.wrapMode = WrapMode.Loop;
function Update ()
this.transform.position + = this.transform.forward * speed;
else if(Input.GetKey("down"))
this.transform.position - = this.transform.forward * speed;
else if(Input.GetKeyUp("up") ||Input.GetKeyUp("down"))
recreated. This would prove quite laborious. A nice thing Unity lets
you do is blend animations to give a more seamless transition.
Step 12. Change all the occurrences of Play in the Update function
with the function name CrossFade.
Step 13. Play. The character will now transition smoothly between
animation states.
Step 14. To make the camera follow the character, move the
view around in the scene until you are looking at the character
from behind in a position slightly up and to the right as shown
in Figure 3.10 . With the camera selected in the Hierarchy, select
GameObject > Align With View from the main menu. Once you
have the camera in a place you would like, drag and drop it in the
Hierarchy onto the Hero game object. The camera will become a
child object of the model and follow it wherever you move it.
Step 15. To add turning and running to the character, the same
format as the existing code is used to test for the left and right arrow
keys for turning and the right shift key for running. When turning, the
model's transform is simply rotated. Modify animationControls.js to
the code in Listing 3.11 .
Search Nedrilad ::

Custom Search