BtKinematicCharacterController is jittery when stationary.

Post Reply
Slight0
Posts: 11
Joined: Wed Nov 19, 2014 12:42 am

BtKinematicCharacterController is jittery when stationary.

Post by Slight0 »

Has anyone run into this issue using the kinematic character controller?

It seems after moving in a direction then stopping, the controller will move randomly on some axes by small amounts (0.0001) per frame. The effect is even worse with a capsule shape.

I came across someone else having a similar issue via google: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=80705

He points out that the "recoverFromPenetration" function is the culprit.

Does anyone know of a solution or know of a better kinematic based character controller that I could make use of. I'd like to avoid writing my own just because I'm not an expert and would rather learn from mature code than trail and error.

Edit: I've found that, indeed, recoverFromPenetration is causing the issue. If you take a look at where it's used in preStep:

Code: Select all

void btKinematicCharacterController::preStep (  btCollisionWorld* collisionWorld)
{
	
	int numPenetrationLoops = 0;
	m_touchingContact = false;
	while (recoverFromPenetration (collisionWorld))
	{
		numPenetrationLoops++;
		m_touchingContact = true;
		if (numPenetrationLoops > 4)
		{
			//printf("character could not recover from penetration = %d\n", numPenetrationLoops);
			break;
		}
	}

	m_currentPosition = m_ghostObject->getWorldTransform().getOrigin();
	m_targetPosition = m_currentPosition;
//	printf("m_targetPosition=%f,%f,%f\n",m_targetPosition[0],m_targetPosition[1],m_targetPosition[2]);

	
}
You can see it can attempt to recover multiple times for whatever reason. It "fails" to recover every time after 4 tries, each time making micro adjustments to the object's position, even if the character controller is stationary on the ground. Something appears to be very wrong with the implementation of recoverFromPenetration, however, I have to experiment with more of the API functions it uses before I can figure out what.

Edit2: I'd also like to point out that I'm testing with a cylindrical shape for the controller and I've tested it against a simple static rigidbody with a cube shape as the ground. The problem does not seem to happen on the cube shape at all, even on the edges. The issue does occur when moving to a static rigid body with a BvhTriangleMeshShape shape. Interesting.
Post Reply