JUMP LOGIC

I am trying to apply a JUMP effect on my game object. However I am doing this by applying force in y direction. However it is not giving an exact effect of jump as this force is not constant. How can I do this ?

If you want to use Unity’s physics to accomplish this, then the logic is simple.

First you apply a large amount of force in the up direction, Vector3.up

public int jumpForce;

void FixedUpdate()
{
  if(Input.GetKeyDown(KeyCode.Space)
  {
    gameObject.rigidbody.AddForce(Vector3.up * jumpForce);
  }
}

Then, be sure your GameObject has a RigidBody component and it is using gravity. You can also check the physics settings of your project and modify the gravity settings, but by default these are set to real world -9.81 for the y axis.

This will first propel your GameObject up, and then unity will handle the gravity. If you do not see any movement when you apply the force, then you are not applying enough. Try higher values.

Alternatively, you can lower the mass of the object.

Of course, you’ll need to write additional force to further the jumping logic, such as making sure the character cannot jump again while still in mid-air.

However I have already tried this… The force does not seem to stay constant