O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Jumping and physics

Now, we are making our character jump by using Physics.Raycast in Unity. We can also use the OnCollisionEnter, OnCollisionExit, or OnCollisionStay functions to check the collision detection between our character and the floor, but in this case we will use Raycast because it's more flexible to adjust.

However, because the Raycast is only a line with no thickness, there is a chance that if we have a very thin platform, the Raycast can miss it. And it will cause the problem that we might not be able to jump. So, we should make sure that the platform should have the thickness of least 0.1 units.

Engage Thrusters

Continuing from the last step, let's get on with it as follows:

  1. Let's open our CharacterController_2D.js file and add this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required