Disable collision in OnCollisionEnter without changing velocity of the colliding rigidbody

I have my player that collides with a platform and if the player is below that platform I want to disable the platform and let the player get on top.

Simple, if I ignore how to enable the collider again for now:

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.CompareTag("Platform"))
        {
            float platformTop = collision.collider.bounds.center.y + collision.collider.bounds.extents.y;
            float playerBottom = col.bounds.center.y + col.bounds.extents.y;

            if (platformTop > playerBottom)
                Physics2D.IgnoreCollision(collision.collider, col, true);
        }
    }

Now if I jump with the player against the platform from below it disables it just like I want it to.
The Problem is that when that happens the velocity of the rigidbody on my player is still changed to 0 vertically because it hit a ceiling.

I’ve tried disabling the collision with:

    collision.collider.enabled = false;
    collision.collider.isTrigger = true;

but the same problem still occurs.

Is there any way to fix this? Can i execute code before the velocity is changed? Or can I prevent a change of velocity in this frame?
Or do I simply have to work around this?

Thank you for any answers :smile:

OnCollisionEnter2D isn’t tellnig you it’s about to collide, it’s telling you it has collided and solved after the fact. There’s no callback that tells you it’s about to collide no.

1 Like

poggers thank you, that what i wanted to know