OnCollisionEnter stops checking once going up or down a slope

Hello, i’m trying to make a movement system loosely on retro shooter, I’m using the rigidbody system and I was having trouble figuring out a good isGrounded method and i came across this.

    //Ground checker
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == ("ground"))
        {
            isGrounded = true;
        }
    }
   
    void OnCollisionExit(Collision collision)
    {
        if (collision.gameObject.tag == ("ground"))
        {
            isGrounded = false;
        }
    }

Which worked mostly flawless being able to move and jump platform to platform without a problem, the problem came when trying go up or down slope, the system would freak out and go that is isGrounded = false; not allowing me to move and start planning across the map.

Any alternatives or fixes for my isGrounded method?
thanks in advance

I’d go with casting a ray (or three) under the player to check for grounded. Walking off a flat surface onto a slope will almost certainly have you lose contact with the ground for a frame or two, especially if you don’t have any special ramp logic in your controller to add extra gravity / keep them in contact with the ground. Rigidbody based character controllers are a lot of work, so be prepared to spend a lot of time refining.

1 Like

I have been working in a RigidBody for a week now and yes character controller is easier, but i found the movement in games that use rigidbody more fun. I was previously using a ground checker method that would check how far a certain point was from the ground, which had another set of problem. I will give the ray a check than. thanks

Here’s a post I came across on reddit recently: Reddit - Dive into anything

It’s about preventing a player from falling off ledges, but you could think of a similar system for sensing stairs/ramps/slopes. Might get you thinking of different ways to approach this problem.

1 Like