Having issues with preventing capsule collider from sliding down inclines

Hello, this is my first help post here.

I’m relatively new when it comes to making custom character controllers, having already tried making something similar to LPGhatguy’s Luanoid (basically a part elevated above the ground using many downward raycasts in a sunflower seed arrangement). I was unsatisfied with the end result as there were many framerate-related issues with it that never seemed to disappear no matter what I tried doing.

So far, I’ve found lots of success with the alternative of using a capsule collider for my character. My current implementation has a VectorForce to control movement, a BodyGyro to keep the capsule standing upright, and an AlignOrientation to make the capsule face the direction the player is moving in (or looking towards if they’re camera-locked). The capsule collider and the ground it’s on also has no friction or elasticity.

Unfortunately, I’ve hit a roadblock in figuring out a good way to prevent the capsule from sliding down inclines. The most successful approach I’ve found so far is using raycasts to determine the average surface normal of the ground the capsule is on and then use said normal to apply a force that’s supposed to be in the opposite direction the capsule is sliding towards. While this approach does work on perfectly flat surfaces, it gets thrown off when the capsule is on multiple differently inclined surfaces at once (e.x. in-between flat ground and the beginning of a ramp), making the capsule gravitate towards/away from an incline which is undesirable for what I want to do. The mp4s below illustrate the issues I’m talking about.

Has anyone who’s seasoned with making custom characters figured out a method of achieving this behavior I’m looking for, minus the issues my approach has? The best alternative I can think of is not using an average of surface normals, but rather getting the points of contact between the ground and the capsule’s bottom sphere then figuring out which point to use in calculating what direction force should be applied in. I’m now sure how I would accomplish this, though.

Thanks in advance.

2 Likes

Can you show us the code for this? It’d help me understand exactly what you’ve already tried and if it’s the same thing as what I’d do.