Stop my player to fall under the ground on high slopes

Hi,
I’m making a 3D game since a while and i always noticed that my player when it comes to high slopes, can’t just stay blocked in front of it but tries to climb and fall through the collider. I don’t know what to do at this point, i think everything is configured correctly.
My player stays on the ground with two legs that have a capsule collider each.
The player doesn’t go that fast.

My colliders are not triggers
The terrain has a mesh collider
I tried putting one single big capsule collider and the same issue occurs.
My rigidbodies are both (player and terrain) continuous dynamic
Making it interpolate doesn’t do anything
My physics update time is 0.2

Here is a picture of my player rigidbody :


And of the terrain rigidbody and collider

Here is the concerned part of the terrain :

Note that i tried with different terrains and it always occurs.

Thanks by advance

Most likely the cause has to do with the way you are moving the player’s rigidbody. Operations like modifying Transform.position, Rigidbody.position or calling Rigidbody.MovePosition bypass the physics calculations, and frequently this is the cause of rigidbodies passing through colliders. The correct way for moving rigidbodies so collisions and frictions are simulated properly is calling Rigidbody.AddForce from FixedUpdate. See:

Apart from that, the terrain doesn’t need a Rigidbody. If you read the console, you’re already receiving errors because rigidbodies can use convex colliders only, and you’re trying to assign a non-convex collider to a Rigidbody. You can just remove the Rigidbody component from the terrain collider, it’s doing nothing.

2 Likes

You may also want to look into Kinematic Character Controller since that handles pretty much all of the hard edge cases that the default CharacterController component doesn’t.

2 Likes

Hello,
Thanks for your help, i understand that my old method was bad, i tried it today and here it is (i use the new input system) :

    //axis
    inputH = inputMove.ReadValue<Vector2>().x;
    inputV = inputMove.ReadValue<Vector2>().y;

    //player movements
    //player movements
    Vector3 movement = Vector3.right * inputH + Vector3.forward * inputV;
    rb.AddForce(movement*speed - rb.velocity, ForceMode.VelocityChange);

That seems to work well concerning the shifting, but when i fall, the player has a non-realistic fall with constant velocity, how can i handle that ? Is it mandatory to check if the player is on the ground ?
On another part, this method makes my jump look weirdly fast on the rise, it is made by a rb.AddForce in force mode. ( i think i can fix it by detecting the jump input and making it a condition to skip the velocity movement command )

You may disable Gravity in the Rigidbody component and apply the acceleration of the gravity yourself:

rb.AddForce(movement*speed - rb.velocity + Physics.gravity * Time.deltaTime, ForceMode.VelocityChange);

For jumping, when the character is grounded and the Jump control is pressed, apply a one-time velocity change like this:

rb.AddForce(Vector3.up * jumpSpeed, ForceMode.VelocityChange);