I have just started playing with the character controller this weekend and also noticed some issues when implementing it.
I will share my findings so that it might help others. I hope more people will also share theirs.
Some issues mentioned ( sliding down slopes etc ) in my case came from the fact that the btKinematicCharacterController is a bit too aggresive when recovering from penetration.
This can easily be seen by outputting the recovery vector in recoverFromPenetration in btKinematicCharacterController.cpp
Code:
btVector3 recoverDir = pt.m_normalWorldOnB * directionSign * dist * btScalar(0.2);
printf("recoverDir=%f,%f,%f\n",recoverDir[0],recoverDir[1],recoverDir[2]);
Even standing on a flat tri-mesh would continuously trigger recovery ( but less noticable when not outputting any debug on the recovery )... and when standing on a slope you will get pushed off because no margin was added for penetration recovery.
A quick fix for this is to add a margin to the recovery
You can change the following
Code:
btScalar dist = pt.getDistance();
if (dist < 0.0)
into
Code:
btScalar dist = pt.getDistance();
if (fabs(dist) > 0.2 /* m_addedMargin? */)
That will atleast fix the continuous penetration recovery and you will no longer get pushed of slopes.
Besides that there is also another "issue" in the stepForwardAndStrafe routine... basically when walking into a slope, with an angle you should not be able to climb, it will calculate a perpendicularComponent based on the collision so that you will strafe/slide along a wall / geometry which is steeper then the max slope angle.
The issue with this is that the perpendicular vector of the collision will also move the character on the y-axis eventhough you are not able to climb the geometry which could result in jitter because of needed recovery after this movement.
When walking into a very steep hill i got:
perpComponent=0.062345,0.075178,-0.084877
Which will let the character slide along the hill as expected but will also every now and then push it up a bit and penetrate geometry and thus it needs to recover which resulted into a bit of jitter.
For now i have "solved" this by setting the y-component to 0. This is pretty dirty and might lead to other errors ( havent had time to do any real testing ) so better is to create a proper fix ( which i think should take the max slope angle into account and possibly check if you are on the ground? ).
in updateTargetPositionBasedOnCollision:
Code:
if (normalMag != 0.0)
{
btVector3 perpComponent = perpindicularDir * btScalar (normalMag*movementLength);
perpComponent[1]=0.0f;
// printf("perpComponent=%f,%f,%f\n",perpComponent[0],perpComponent[1],perpComponent[2]);
m_targetPosition += perpComponent;
}
As i said i just started playing with the character controller so if someone has better ways to fix some of the issues please let me know.
Besides these issues the character controller does a pretty good job and i dont think that most other issues are hard to fix.
P.S.:
Im dutch so please dont mind my english.