Page 1 of 1
Kinematic Character Controller - Inconsistent Jumping
Posted: Sun Oct 15, 2017 2:03 pm
by Silverlan
I'm using a
btKinematicCharacterController with a capsule shape for my player character. Everything works smoothly, however when I try to implement jumping by adding an upwards force, the result is very inconsistent:
https://youtu.be/e1MsiUosjDk
Sometimes the character is jumping higher, sometimes lower, for seemingly no reason.
The force is just being added as linear velocity:
Code: Select all
PhysKinematicCharacterController *c = getKinematicCharacterController();
c->setLinearVelocity(c->getLinearVelocity() +btVector3(0.0,5.0,0.0));
It only seems to happen when the character is standing on something, so it might have something to do with the ground collision?
Does anyone have an idea what I can do about this?
Re: Kinematic Character Controller - Inconsistent Jumping
Posted: Mon Oct 16, 2017 3:29 pm
by drleviathan
Where do you call that code? Before the world->stepSimulation() or in code that is executed every substep?
If the latter then it is possible for your world to make two substeps in a single step (depending on how you setup stepping, but I assume you do something sane and normal) which might cause your code to be called more than once.
Perhaps you should use btKinematicCharacterController::canJump() and btKinematicCharacterController::jump(velocity)?
Re: Kinematic Character Controller - Inconsistent Jumping
Posted: Fri Oct 27, 2017 4:55 pm
by Silverlan
drleviathan wrote:Where do you call that code? Before the world->stepSimulation() or in code that is executed every substep?
If the latter then it is possible for your world to make two substeps in a single step (depending on how you setup stepping, but I assume you do something sane and normal) which might cause your code to be called more than once.
Perhaps you should use btKinematicCharacterController::canJump() and btKinematicCharacterController::jump(velocity)?
It doesn't seem to matter where I call it, and
btKinematicCharacterController::jump(velocity) has the same effect.
The problem only occurs if the character is standing on ground when jumping. If I move the character slightly above the ground and then add the velocity, the jump height is always the same.
I think it has something to do with collision detection, my guess is that bullet thinks the character is still colliding with the ground right after the jump, and that causes a slowdown. I can't figure out what to do against that though.