I recently moved from Bullet to PhysX to see if it would be a better solution for my game engine, and so far it is. The only problem that I'm having, which is part of the reason that I switched is with the character controller. The build in one is pretty good, but I've run into an issue when I walk down a slope (although up is fine). Because the player walks faster than gravity pulls him down (I set it to 0 when he is on the ground), he detaches from the slope, which obviously is not desirable.

I've considered and tested several ways to fix this. One idea that I had was to check if there was ground below the character once he moved in the xz-direction, with a distance less than or equal to to the magnitude of that vector because I decided that a 45º slope was what the character could not walk up. That had a huge amount of problems and resulted in a lot of teleporting.

Then I tried to make it so when the player was on the ground that a really high gravity would be applied to keep him on the slope. This also didn't work because if the character was on the ground and then moved over a cliff, he was on the ground before he walked over the cliff he would be teleported down.

I'm really not sure how to progress here because logically the problem has stumped me. I took a look at some of the behavior of the Unreal character and it doesn't seem to suffer from any of these problems and it uses PhysX, so obviously they found a solution.

If anyone has any ideas, I would appreciate it.



For anyone who hits this problem in the future, a possible solution is to implement a "surface follower". It's one of those special-case movement things that will save you a lot of heartache to know about.

Instead of relying on physics to handle slopes, you branch into your surface following code, which uses e.g. a PhysX world collision raycast to find the ground directly beneath the mover. It then snaps the follower's position to the ground it hits, if the hit point is within a set threshold. If the surface is too far below the character, put them into "falling mode", and let them fall until their capsule hits the ground (i.e. don't snap to surface as soon as it gets to the threshold).

The length of the raycast should be long enough such that stairs and slopes within desired steepness should not be detected as causing "falling mode".

By having this special-case code, your game is now much more tuneable, because you can pick hard numbers for how steep slopes can be, and reliably see following on those slopes.

Surface followers are useful even in 2D, where small boundaries between collision objects can cause hitching.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.