Game Development Reference
In-Depth Information
stops (because it is not set to loop), animations in the next lower layer
can play. In this case it will be the idle and walk cycles. Press play to see
this in action.
Step 8. Note that when now shooting, the entire shoot animation
plays; however, it ends abruptly as the shoot animation finishes and
the character jumps back into the idle animation. This can be fixed
by blending the animations together to give a smoother transition.
Instead of using the Play() function, CrossFade() is used to blend the
current animation with a new one. Modify your code with the changes
in Listing 3.26 .
Listing 3.26 Blending Animation for Smooth Transitions
private var speed = 0.03;
...
function Update ()
{
...
if(translation > 0)
{
this.animation. CrossFade ("WalkForward");
}
else if (translation < 0)
{
this.animation. CrossFade ("WalkBackward");
}
else
{
this.animation. CrossFade ("Idle");
}
if(Input.GetKeyDown("space"))
{
this.animation. CrossFade ("ShootStraight");
}
...
}
Step 9. Play. Note how the transition between animation states is
smoother.
Step 10. The last issue to take care of is the shooting while moving.
Currently, if the character is moving and the space bar is pressed, the
character will play the shoot animation and slide along the ground. You
can deal with this in two ways. Stop the character moving and shooting
Search Nedrilad ::




Custom Search