Game Development Reference
In-Depth Information
Here, we've checked to see if the player is moving left or right and then gave the
player an impulse force based on its current movement direction. The last thing we
need for jumping to work is to add the adjustable variables used in the AddForce
command. At the top of PlayerStateListener , add the following public variables:
public float playerJumpForceVertical = 500f;
public float playerJumpForceHorizontal = 250f;
Now, with these, you can easily and quickly adjust the values to find what seems
best for you and your game.
Go ahead and play the game and press the jump button as assigned in the Input
Manager for your project. By default, the jump button in Unity is always the Space
bar. Your player should now jump up! You can even jump left or right while running
for a running jump. Landing, on the other hand, doesn't do anything right now.
Let's change that.
Wouldn't it be cool if the player did an animation while jumping?
Using what you've learned about animations and changing
between them, challenge yourself to add in a jump animation!
Not missing the ground
What we are going to do now is make the player register whenever they have landed
on a platform. To do this, we will work with colliders that allow us to be certain not
only of when we land, but also what we land on.
We could have checks that verify whether the player is moving
vertically or not, and then automatically set the landing state based
on the vertical movement state. However, this has a number of
drawbacks including being less flexible than the method described
on the following pages, and if the player slows down enough in
mid-air to not be moving for a moment, the game could actually
register that they landed! So instead, we will work with colliders,
which allow us to be certain of when we land and what we land on;
we will automatically set the landing state based on that information.
Now, let's perform the following steps:
1.
Select a Platform object.
 
Search WWH ::




Custom Search