Since my dynamic controller does not work as expected, I still didn't give up on the btKinematicCharacterController. I reimplemented the code from the CharacterDemo in my app, and I noticed a few strange things, but these are all present in the original demo as well. I see people using the built-in character controller succesfully for simple projects, but no one seems to have asked these questions, no matter where did I search.
The first thing is, why the character controller can't push dynamic objects correctly? Regardless of the object's mass or material configuration, it can't be pushed by the character. For example, I have a rigid body cube, and a kinematic character controller capsule. When there's a head-on collision with the box, the box will jiggle a very little bit (indicating that the character has came in contact with it), the character controller starts shaking (looks like it's trying to penetrate the box repeatedly, even when CCD is turned on), but the box will "win", the character controller simply slides off from the side of the box it was facing.
But, for some reason, when the capsule hits the box diagonally (what my character normally doesn't), it is able to push it to a varying distance correctly, then it locks down as in the previous case.
This very same thing happens in the CharacterDemo as well, if you shoot a small cube somewhere, then you try to push it with the character, there's a chance that it will push it correctly (but again, only to a limited distance), but most of the time, it exhibits the same behavior as my app.
The other curious problem is that even if the simulation runs at a fixed timestep, the movement depends on the framerate. And to make it more strange, the lower the framerate, the faster the character moves. Again, both in my app and the CharacterDemo.
Any clues about these?
And here's a problem that only happens in my app: even if the initialization/destruction code is the same as in the demo, I have a small (40 bytes) memory leak when using the kinematic character controller.
Here's the destruction code:
Code: Select all
void GameState::exit()
{
/*The 3D engine's clean-up stuff goes here.*/
if(kinematicPlayer)
{
delete playerController;
}
for (int i=phyWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* obj = phyWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
phyWorld->removeCollisionObject(obj);
delete obj;
}
delete m_pGroundShape->getMeshInterface();
for (int j=0;j<m_collisionShapes.size();j++)
{
btCollisionShape* shape = m_collisionShapes[j];
delete shape;
}
m_collisionShapes.clear();
delete dbgdraw;
delete phyWorld;
delete mSolver;
delete mBroadphase;
delete mDispatcher;
delete mCollisionConfig;
}