PlayerController - jump

Floor:

Create an empty gameObject, rename to Floor Add BoxCollider2D as shown in image below Select and icon for the gameObject - select in top section of inspector - example green oval Set Layer: Ground, after following directions to create custom layers below.

Floor: Empty GameObject with BoxCollider

Unity Configuration Steps: Jumping Player

In order to use the following script to enable your player to jump, the following changes must be configured in Unity before the following script will work

Custom Layer: Ground

  • Create a new Layer: Ground in the Unity Layer Editor. All gameObjects which will act as ground, (example: Floor) to allow jumping, must have this layer set in the inspector. See image below

  • Set the Layer: Ground for all gameObjects that the player should be able to jump from. Example: Floor

  • GroundCheck: Create an empty gameObject, make it a child of the Player, name: GroundCheck. Add an icon (orange capsule in the image ), so it's easy to see. Move the GroundCheck gameObject to the bottom of the player's feet, this gameObject will check to see if it's in contact with a gameObject that is in the 'Ground' layer.

PlayerController - with jump Code

Populate New Items in Player: Inspector PlayerController Component

Last updated

Was this helpful?