- Home /
Disappearing platform problem - RigidBody2D and BoxCollider2D
I've been banging my head against a wall trying to figure this out.
I'm programming a 2D platformer and I am trying to make a platform that disappears and causes the character to fall through. The character has a rigidbody2d and boxcollider2d component and I have a platform set up that reduces its own alpha and eventually disables its boxcollider2d for a period of time after the player touches it.
If the platform has disappeared and the player walks over it, they fall as expected. But if the platform disappears while player is standing on it, the character does not fall through and acts like it is still standing on the platform.
Here is my collision code -
//When staying in a collision
void OnCollisionStay2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
foreach (ContactPoint2D contact in collision.contacts)
{
if(contact.normal == down) //down = Vector2(0.0f, 1.0f)
{
ac._isGrounded = true;
ac._canJump = true;
}
}
}
}
//When exiting a collision
void OnCollisionExit2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
ac._isGrounded = false;
ac._canJump = false;
}
}
Wouldn't disabling the platform's collision box cause OnCollisionExit2D to kick in and change the variables?