Hello,
I'm trying to implement character movement so that my character would slide along the wall (plane) instead of getting stuck next to it.
There is quite a lot of information regarding character sliding on the internet. However all that information seems to be covering only basic cases where character slides only on one plane at a time (collides with one plane at a time). I could not find any information about how to solve corner cases with multiple planes for example where character collides simultaneously with two walls and ground.
My current implementation's general idea is to:
1. calculate the movement velocity vector (intended position change)
2. try to move my character along that vector if vector length is bigger than some epsilon.
2. a. If there is no collision I update the position and I'm done.
2. b. If there is a collision, I move character to the TOI (time of impact),
3. then for the remaining velocity vector I calculate new velocity vector depending on collision normal and repeat the process (go back to 2.)
This seems to work in simple cases, when I'm dealing with one plane (ground for instance). It also seems to work if I simultaneously collide with two objects (ground and wall) if two collision normals are perpendicular. However if angle between two simultaneously collision normals are less than 90° (like "V" corners), my new velocity vector (3.) starts bouncing back and forward between these two surfaces and I need quite a few iterations to resolve the final position. The smaller the angle the more iterations I need. If it was 2d I probably could just stop the algorithm and bale out if I find out that I'm "bouncing" between two surfaces, but in 3D every time I "bounce" my velocity vector slowly changes direction away from current collision normals. But as I said it takes quite a few iterations to get the final result, and this causes freezes, I could limit the iteration count however this might cause my character to stick to a wall instead of sliding along it as I would never reach the correct length of sliding vector.
Some engines like "DigitalRune" move character to the final position, then check for collisions and tries to resolve the final position, in that way you get the sliding effect. This could work in my case as well, however I'm using GJK for collision detection, so I could only solve shallow penetrations, not bigger than 2xMargin. Maybe after first collision and finding TOI I should move my character in smaller steps (not bigger than 2xMargin) for the remaining velocity. In that case I could resolve penetrations. This might work, however it seems that again I potentially can get a lot of iterations. Secondly, by resolving penetration my character might get stuck in another object.
I found one quite fresh topic related to mine:
Randy Gaul says that after finding TOI and collision normal "<..>calculating resolution terms is trivial". Sadly, I find it not that trivial ?
I know that all my rambling is confusing and hard to understand, but I hope you'll be able to give me some tips.
Any help will be appreciated thank you.