I have a terrain with geometry that is fairly ridged. I needed to make sure the player didn't enter the world geometry, so I used sphere-triangle intersections (after narrow down of which tris to test using AABBs on chunks of the terrain).
This works fine, the player smoothly appears to "roll off" the terrain when you walk into it.
What I do is detect the penetration distance of the sphere into the terrain, then just push the player back in the direction of the terrain face. That clears him of the world geometry.
Method 1:
Push the bounding sphere of the player back in the direction of the normal of the wall he hit, until he exits the wall.
However. This has had the awkward side effect of occassionally pushing the player into another face (when the player is near the meeting of 2 faces). The result is this nasty bounce-shake between the two walls and the player gets stuck until he changes direction (turns around).
Initially I tried to solve this problem by:
"Cancel" previous move by translating player back along his "last move" vector the exact distance he moved if he touches a wall
- But this causes walls to feel "sticky". You will get "caught" on walls if you use this, if any component of your velocity enters a wall (so you cannot "slide" by running diagonally into the wall).
Pushing the player back along his "last move" vector only far enough to clear the wall. This looks better at first, but converges to the same sticky walls problem as "fully cancelling the move" if the player is already touching the wall, but is trying to slide along it by running diagonally into it
Method 2:
Cancel or partially cancel the move by pushing the player back along the vector from which he came, until he exits the wall he deepest hit
So it seems I was on the right track with the first approach (push in wall's normal direction). What I'm going to try next is a hybrid:
- Look for wall intersection
- If one is found, push him back along the normal of the wall, then CHECK FOR A WALL COLLISION AGAIN (apply Method #1)
- If a 2nd wall collision is found, cancel the move until he exits the wall (apply Method #2)
- If one is found, push him back along the normal of the wall, then CHECK FOR A WALL COLLISION AGAIN (apply Method #1)
Am I on the right track here? Is there a better way to solve this?