Game Development Reference
In-Depth Information
Make 'em run!
Ready for a challenge?
This is where we take a bunch of the things that were taught through this first part of
the topic and combine them into a culmination of events. We'll call this: CHALLENGE
1 . If you just heard a thunderclap and electric guitars after reading this, it's perfectly
fine—you're not alone.
When you look at the player, you may notice one very major issue. When it runs, its
orientation doesn't change. The player stays facing one direction and never plays its
run animation.
This is where we fix that.
Let's update the state code to change the Boolean Walking state of the player's
animator component. Open PlayerStateListener.cs and access the state in
onStateChange(newState) . Let's add the ability to play the run animation. Change
the entries for idle , left , and right of the state code to look like the following:
case PlayerStateController.playerStates.idle:
playerAnimator.SetBool("Walking", false);
break;
case PlayerStateController.playerStates.left:
playerAnimator.SetBool("Walking", true);
break;
case PlayerStateController.playerStates.right:
playerAnimator.SetBool("Walking", true);
break;
With that one small change, you can now switch between the run and idle
animations. Play the game again, and you will see the player running while moving
and idling when not moving!
OK, this covers half of our current problem. Next, we need to solve that little always
faces the same direction issue. There are quite a number of ways to solve this.
The easiest, however, will be to flip the horizontal scale of the player object.
Sounds crazy? Think of it this way, if you scale something from 1.0 to -1.0, it's now
facing the opposite direction. This works even with us using a one-sided plane
because we do not actually flip the plane to its other side—all we are doing is
reversing the order in which its vertexes are rendered, causing it to render as if it
were mirrored. This couldn't really get much easier, could it?
 
Search WWH ::




Custom Search