#2D Platformer Collision Detection

1 messages · Page 1 of 1 (latest)

warm glacier
#

[Solved]

Hi everybody, thanks for taking a look at this for me.

I am having an issue with my platforms in my 2D Platformer. I have things set up so that if the surface is flat-ish, I ought to be transitioning from my airbourne state to my grounded state. However, on my tilemap collider 2D that I am using for my platforms, I am having the strange issue where if

  1. I touch the 'surface' from a side angle,
  2. Hit another flat-ish surface that is part of the same tilemapcollider2D
  3. My character will be stuck in the airbourne state

Video and code in the thread.

#

Here is my TilemapCollider2D

#

Here is my collision handling method.

    public override void HandleCollision(Collision2D collision, CollisionType collisionType)
    {
        if (collisionType == CollisionType.Enter &&
            collision.collider.CompareTag(Tag.Platform) &&
            SurfaceIsFlat(collision))
        {
            Airbourne(false);
            jumps = 0;
            player.Rigidbody2D().linearVelocityX = 0;
        }
    }

my tilemap game object tag has the value Tag.Platform

#

and here is my SurfaceIsFlat check

        protected bool SurfaceIsFlat(Collision2D collision)
        {
            return Vector2.Dot(collision.GetContact(0).normal, Vector2.up) > flatSurfaceBounds;
        }
#

I suspect this has to do with the fact that I am only checking on enter

#

So if I make contact with the TilemapCollider2D the first time, the OnCollisionEnter2D method does not fire again.

#

Yup. Thanks rubber ducky!