Be sure your character has a Rigidbody attached, and no Character Controller (if you're intending to move this character with physics)
Ensure the character's Rigidbody is set to dynamic, and its constraints allow movement on the y axis
Disallow rotation on the Rigidbody, to keep your character from tipping over accidentally
Verify that the character's collider is not interpenetrating with any scenery that might trap them in place
Use velocity changes or impulses to set velocity, not forces
Here's a simple jump script that helps fix a couple of these:
// This tells the editor to enforce "only use this script on objects with Rigidbodies".
[RequireComponent(typeof(Rigidbody))]
public class Jump : MonoBehaviour {
public float jumpHeight
[SerializeField, HideInInspector]
float _jumpVelocity;
[SerializeField, HideInInspector]
Rigidbody _body;
// When you tune the jump height in the inspector, automatically
// calculate the physics values that will get you to that height.
void OnValidate() {
// Cache a reference to our body so we don't have to search at runtime.
_body = GetComponent<Rigidbody>();
// Solve v(t) = v(0) + a * t for v(t) = 0.
float secondsToJumpApex = Mathf.Sqrt(-2f * jumpHeight / Physics.gravity.y);
// Substitute into h(t) = h(0) + v(0) * t + (a/2) * t^2 and solve for v(0).
_jumpVelocity = Physics.gravity.y * secondsToJumpApex;
}
void Update() {
// Use a named input set up in the Input Manager, not a hard-coded key.
if (Input.GetButtonDown("Jump")) {
// Jumps are instantaneous, so use VelocityChange instead of a gradual push.
_body.AddForce(jumpVelocity * Vector3.up, ForceMode.VelocityChange);
}
}
}