Kinematic Character Controller - Inconsistent Jumping

Post Reply
Silverlan
Posts: 27
Joined: Thu Oct 30, 2014 9:15 pm

Kinematic Character Controller - Inconsistent Jumping

Post 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?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Kinematic Character Controller - Inconsistent Jumping

Post 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)?
Silverlan
Posts: 27
Joined: Thu Oct 30, 2014 9:15 pm

Re: Kinematic Character Controller - Inconsistent Jumping

Post 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.
Post Reply