I’ve noticed that a lot of people seem to have this issue but I’ve yet to find an actual working solution - when a rigidbody-based character controller (I’m not using Unity’s character controller) moves down a sloped surface, they will bounce/bunny hop on the way down instead of staying on the surface. I’m building a 3d platformer and ran into this issue - I’ve tried a fair amount of things but nothing seems to work cleanly. I managed to find a 2D solution here but I can’t seem to get it to work cleanly in 3D. Here is my code:
void NormalizeSlope()
{
// Attempt vertical normalization
if (isGrounded)
{
RaycastHit hit;
if (Physics.Raycast(floorCheck.position, Vector3.down, out hit, groundCheckDistance))
{
if(hit.collider != null && Mathf.Abs(hit.normal.x) > 0.1f)
{
// Apply the opposite force against the slope force
// You will need to provide your own slopeFriction to stabalize movement
rigidbody.velocity = new Vector3(rigidbody.velocity.x - (hit.normal.x * 0.4f), rigidbody.velocity.y, rigidbody.velocity.z); //change 0.6 to y velocity
//Move Player up or down to compensate for the slope below them
Vector3 pos = transform.position;
pos.y += -hit.normal.x * Mathf.Abs(rigidbody.velocity.x) * Time.deltaTime * (rigidbody.velocity.x - hit.normal.x > 0 ? 1 : -1);
transform.position = pos;
}
}
}
}
With that, I get varying results on surfaces with different slopes. Also, my character jitters. On some slopes, my character even slowly inches their way up the surface. Has anyone else run into this issue? Does anyone have a working solution for this problem?