Game Development Reference
In-Depth Information
The Physics.Raycast is used to check if our character is on the floor or not. If it isn't,
it will tell the game that now our character isn't on the floor, making its state equal to the
jumping state (or we can say that it is in the air). By using this checking statement, we will be
able to play a jumping animaion when our character is falling down, but the player doesn't
press the jump buton.
We also draw three rays:
1. We draw the ray from the middle of our character to the botom.
2. We draw the ray at the very right bound of the object to the botom; we won't draw
the ray at exactly the right bound posiion because we don't want it to hit the edge
thickness of the floor.
3. Then, we do the same thing as with the right bound to the left bound.
Next, we check to make sure that the ray didn't hit anything and our character isn't jumping.
We check the last Y-posiion for our character—whether it is equal to the current Y-posiion
or not. If it is, it means the character is on the floor, so we set b_isJumping = false . If it
doesn't, the character will fall down and we set b_isJumping = true . Finally, we update
our character's last posiion on the Y-axis.
Next, we want the OnDrawGizmos() funcion to show our Physics Raycast in our editor
scene which will give us a nice visual to see our Ray poining to the right direcion. In this
funcion, we will use Gizmos , which is the class that basically allows us to draw the visual
debugging or set-up aids in the scene view. We can get more informaion on how to use
Gizmos from the following website:
http://unity3d.com/support/documentation/ScriptReference/Gizmos.html
Lastly, we create another Sprite class to manage our jumping texture to show the jumping
animaion by checking its velocity in the Y-axis. In the JumpSpriteManager , we almost
have everything similar to our SpriteManager . Since we don't need a loop animaion in
this Jumping Sprite, but we sill need to change the texture. First, we will change the main
texture to t_jumpAirTextures , which will show the sprite while the character is at the
top in the air. So, we check the velocity in the Y-axis, to see if it is between -2 to 2. Next,
we check if the velocityY is greater than 2. This means that the player has just started
jumping, but anything other than that means our character has fallen. Finally, we update our
character's Tiling and Offset .
Classified Intel
There is something else we must look at in this chapter—the Physics.Raycast .
 
Search WWH ::




Custom Search