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?
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 :
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.