How do I set a specific force to a rigidbody?

This is my first question.

Ok so I have an object. It’s y is set to be between 0 and 3.

I want the object to jump when I press the jump button so I gave it a rigidbody, gravity and set it so that when I press jump it adds forse for the jump. But it dosn’t work.

From what I see AddForce just add some force, it doesn’t set the force to a value. How do I set a specific force to a rigidbody?

Here is my script

	//jumping
	if ((Input.GetButtonUp("Jump")) && (transform.position.y <= 0))  
    {
    rigidbody.AddForce(Vector3(0,Jump,0)); 
    }
	transform.position.y = Mathf.Clamp(transform.position.y, 0, 3);

please help

The problem is you want to add an instantaneous force, where AddForce is applied over time in physics. For an instantaneous force in your case of hitting the jump button once, you need to use ForceMode.Impulse :

 rigidbody.AddForce( transform.up * jumpForce, ForceMode.Impulse );

or using your script :

 rigidbody.AddForce( Vector3(0,Jump,0), ForceMode.Impulse );

Links :

If you want to use forces, don’t set the transform’s position. Just add force. The magnitude of the vector is the amount of force added. The force doesn’t correspond to the amount of units you want to move, so you’ll have to experiment how much force to add.

You should read the physics documentation to under how to work with rigid bodies.