Let me introduce you to the problem. Imagine a box with a kinematic object inside. The floor of the box is stair-like. Sort of like Qbert.
Now, if I move the kinematic object near a wall and then slide it to right or towards the observer, it will "stick to walls" and won't fall downstairs.
I've searched a bit the forums. The popular solution seems to be playing with the collision margin. This is also done in the sample code. It looks like
Code: Select all
const btScalar addMargin = .02f; // value used in CharacterDemo. People seem to play with values from .1 to .3 (?)
const btScalar prevMargin = convex->getMargin();
convex->setMargin(prevMargin + addMargin);
...
ghostObject->convexSweepTest(convex, fromw, tow, collector, conPen);
...
convex->setMargin(prevMargin);
Strangely enough, I cannot find any reference to the problem in other messages.
Right now, I don't even use the above method at all, since I cannot see any difference in avoiding the "stick to walls" effect.
I initially considered this to be a problem of the collision mesh (I'm using a convex hull), which I supposed was getting minimally stuck between different stacked boxes. Like this:
Code: Select all
+----+
| |
+----+ /-\<-- hull gets stuck between those two boxes?
+----+ \_/
| |
+----+
So I considered my dual-approach to animating kinematic objects, I even rewrote it, dropping the current ballistics-based method to a RK4 integrator. It somewhat got better, but it still gets stuck... in even stranger ways. Right now, the object will "tick down" till hitting the floor and then rest there perfectly. It thought it was a problem dealing with integrator's refresh rate but as the integrator is ticked at 60hz, I'm not entirely sure I can link the problem to it.
Nonetheless, the unintended behavior is easily reproducible... I'd say deterministic. So I am inclined to think I am missing something fundamental here.
I'd appreciate all forms of help. I'm not entirely sure I fully understand btKinematicCharacterController either.
At this point, I think I will leave it as is for a while and go back a few days from now.
I grow confident that perhaps I should write a more aggressive penetration recovery against walls so I move away from walls much more than from floors.