# Jump independently of gravity

Hello,
I extended the BetterCharacterControl to add double jump functionality. This is working fine so far (I simply have a jumpCounter > 2 test) but the problem is that the character jumps dependent of the gravity. Of course this is the physically correct behaviour (when you fall and apply the same impulse as you do when you stand, you will of course not jump as high) but I don’t want it for my game. So I guess I’d have to multiply the impulse vector in the y direction by the current downward velocity or so? I don’t really get what I neeed to do and how to get the values that I need.

So far I tried:

``````float vel = rigidBody.getLinearVelocity().y;
if(vel > -1) {
vel = -1;
}
rigidBody.applyImpulse(localForwardRotation.multLocal(rotatedJumpForce).mult(-vel), Vector3f.ZERO);
``````

but that gives me too big values so my character jumps far to high after falling. When adding the vector it doesn’t work neither… But that was rather a wild guess…

Thanks

Tbh it shouldn’t depend on whether you are falling down or not.

The physical correct way would simply deccelerate your falling speed.

If you want to make the Player jump whilst falling, how about setting the velocity to zero and then apply the jump force?

Other than that you have that formula:
a is the Derivation of your velocity. You need to find a time in which the falling should be stopped.

Imagine you fly with 10 m/s and want it to stop in 2 seconds you need 5 m/s^2 (10/2)
The force you need to apply is now F = m * a which means if your character weighs 100kg you have to apply 500N over a period of two seconds and then jump.

I would go with the first one though. Set velocity to zero (atleast in y direction) and then jump.

On the other hand it would be better to simply use a high enough jump force this makes it more realistic.

Yeah well depending on the falling speed, it sometimes makes the character jump a bit and sometimes the falling speed is being decreased.

But it was simply late yesterday… Thanks @Darkchaos, setting the falling velocity to zero worked:

``````Vector3f vec = rigidBody.getLinearVelocity();
rigidBody.setLinearVelocity(new Vector3f(vec.x, 0, vec.z));``````
1 Like