Rigidbody2D AddForce only working with large numbers

I have a character that I am trying to make jump. I can make them move left and right with inputs and setting velocity and what not, but the jump isn’t working. I’m using AddForce like so:

“Jump” appears in the console so the function is being called, but the character doesn’t move. However, when I put the number being multiplied in the function (125) to something really high like 500, the character shoots up in the air. Does anyone know why it is working like this?

Figured it out. I had the gravity scale set super high on the associated rigid body 2d.

A few things here:

  1. You’re applying force every fixed update frame. This means you are apply this force around 60x per second. This means by the time the character leaves the ground a lot of force has been added.
  2. Think of reality. If you jump do you continually have a force pushing you upward? No. It’s more of an instantaneous force. For this reason we most commonly use ForceMode.Impulse which applies the amount of force indicated times 1 second. So the total force that would be applied over 1 second of time is applied instantaneously. Force = mass * distance / time^2.
  3. Don’t do this with Input.GetButton, instead use Input.GetButtonDown to only register a single keypress until the key is released and pressed again.
  4. Make sure you have your drag set up properly (usually little drag is appropriate) and make sure your mass is sufficient (usually 1 is OK). Other than that double check your gravity is set to -9.81 m/s^2.
  5. Last one, don’t ever put Debug.Log statements in an Update loop, they block the main thread and slow your application. Learn how to debug things like this with OnGUI or exposing variables in the inspector.