Object won't move when velocity changes via AddForce

Here is my code:

                GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 10), ForceMode2D.Impulse);

Whenever I press space and look in the inspector, the Y velocity goes up by 10. However, the object doesn't move. The RigidBody is set to dynamic and the code only stops moving the object up when I add the space portion.

What does the "jump" variable mean? Should you perhaps name it to "canJump"? Just "jump" sounds like it represents a user intent to jump but that cannot be because you're checking it on line 2.

Either way, time to start debugging to find out if any of your code is even running.

By debugging you can find out exactly what your program is doing so you can fix it.


Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don't assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If you just need a 2D jumping controller:

Coyote Time Jumping and disconnecting input gathering from input processing: