Jumping With Force

I have a simple question. In a script attached to a cube, how do I apply a changeable force that shoots the character in the air. (Jump)
As well as that, how do I make sure the character is on the ground when it jumps.

In C#

A simple approach for checking for grounded is to perform a SphereCastdownward from your player a certain distance (just far enough to reach the player’s feet) and see if you hit any layers that you consider to be “ground”. Do this in Update and set a local property (such as _isGrounded) to true or false based on the SphereCast result.

For jumping, make sure the object has a Rigidbody, then call AddForce, such as rb.AddForce(rb.gameObject.transform.up * rb.mass * JumpStrength);, where JumpStrength is some constant you define in your script to determine how much force to exert.

Thank you for the help, however it says that rb does not exist in the current context. Is there a ‘using UnitySomrthing’ I am missing

The post probably meant for you to create a variable ‘rb’ of type Rigidbody (or Rigidbody2D if it’s 2D). Probably at the class level, assigned through the inspector or in Awake(), and used throughout the script. :slight_smile: