Trouble detecting when Rigidbody2D character lands. (Not so simple)

Hello all,

I need help checking if my RigidBody2D character has landed from a jump. I can’t seem to think of a way to get around these issues:

Must allow for PlatformEffector2D for one way platforming. This means we can’t simply raycast below us or else when we jump through a platform from below, we will be considered ‘landed’ or ‘grounded’ in the middle of our jump.

Must allow for jumping onto slanted platforms. We also can’t simply check to see if the y velocity is <= 0, because if we jump onto a slanted platform and continue running uphill, then our velocity never drops below or = 0.

Jumping right after landing must feel reactive. I mention this because I would just use OnCollisionEnter2D and check the impact point’s normal, but OnCollisionEnter2D feels incredibly delayed, and seems like it’s getting called late, which is kind of annoying.

I’m not really sure what other approaches I can take that don’t get messy, so if anyone has any suggestions please let me know! I’ve been struggling with this for a while, and would like to move on.

Thanks everyone,
Lawrence

So I did find a way to detect when a rigidbody lands. I compared the angle of the Rigidbody’s velocity to the angle of the ground below the player. If the velocity is perpendicular or tilted toward the negative normal, or there is no velocity, then we can assume the rigidbody has landed. I don’t know if using raycasts in this manner will behave properly with PlatformEffector2D colliders, but so far so good…

So my formula looks something like this… hit is a downward raycast a short distance to the ground.

                if (Rigidbody.velocity.sqrMagnitude == 0)
                    IsJumping = false;
                else
                {
                    float VelocityAngle = Vector2.Angle(-hit.normal, Rigidbody.velocity);

                    if (VelocityAngle <= 90)
                        IsJumping = false;
                }