Make a rigidbody Jump (global up)

Hi, I am attempting to make a rigid body jump upwards (global)
The script which i have tried to use doesn’t seem to work.
All help is appreciated.

    function Update(){
	if (Input.GetKeyDown (KeyCode.Space)){

    rigidbody.AddForce (0, 10, 0);
}
}

First off, put that in FixedUpdate. Otherwise, try using this-

rigidbody.AddForce(new Vector3(0, 100, 0), ForceMode.Impulse);

It’s possible that you just aren’t seeing anything because the force is too low!

The easiest way is to set the rigidbody.velocity directly (you will not depend on the object mass):


var jumpSpeed: float = 8;

function Update(){
    if (Input.GetKeyDown (KeyCode.Space)){
        rigidbody.velocity += jumpSpeed * Vector3.up;
    }
}

Apparently this is the new AddForce thing

Public float jumpSpeed = 5f;//or whatever you want it to be
public Rigidbody rb; //and again, whatever you want to call it

void Start (){
   rb = GetComponent <Rigidbody>();
}

Void FixedUpdate(){
   if(Input.GetKey (KeyCode.Space)){
      rb.AddForce(Vector3.up * jumpSpeed);
   }

}

and in the inspector just drag the Player game object from the hierarchy to the rb slot in the script and you’re good :3