- Home /
Addforce while compensating others
Hello.
I'm having troubles with a basic problem, I want my character to be able to jump in the same way whether he is on the ground or on air (he could possibly fall) using AddForce.
Basically when the player is falling his velocity (Y axis) is negative, I would have to manage to compensate for this strength.
Any ideas ?
Answer by xxmariofer · Sep 24, 2020 at 09:14 AM
wll the best solution is to set the velocity to 0 before you add the force somethig like this
yourRigidbody.velocity = Vector3.zero;
yourRigidbody.AddForce(...);
I already implemented this in my player controller but it doesn't work well because I want to preserve the inertia of the player. Even if I set the velocity to 0 on the Y axis only before the jump it makes conflict with my move method resulting in undesirable movements.
I actually want a way to fix this where I add a force to jump while compensating the eventual negative velocity on Y axis.
Thanks anyway.