Avoiding stick on walls

MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Avoiding stick on walls

Post by MaxDZ8 »

Ok, I've spent two days on this, even rewrote a large part of the management, but I cannot quite get this fixed.
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);
This actually didn't help. Big margins would eventually get me stuck on the floor as well so it mandated I couldn't use the same code for sliding over a surface. At the very best (played quite a bit with this), the object would appear to float above. It often would appear to "lift up" when starting to move and "land" at the end of the movement (this is a side effect of previous management, which simulated gravity in another piece of code).

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 rewrote the collision volume generator to avoid those cases. It didn't change anything.

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.
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Avoiding stick on walls

Post by MaxDZ8 »

Replying to my own post just in case this can help other people.
It turns out that because of a bug, the RK4 integrator never really interpolated positions. This made the "ticking" problem go away.

I'm still not sure how to manage that correctly. I've experimented with collision normals and increased penetration recovery displacement from walls. This introduces a slight warp, but because I apply this at the beginning of the movement, it's not really disturbing. I will have to look at this in the future to deal with friction-based response but hopefully this will be sufficient for a while.