Ahh that makes sense then, my expectation here was that when the object passes through the platform, the OnCollisionEnter2D would not be called since the colliders are not “colliding” since it passes right through. For me I don’t consider that a collision as the platform collider isn’t stopping the ball from going through.
In my case it looked like collision in context because of the way I handle the reflection off of surfaces for the ball.
When I encounter a collision by receiving the OnCollisionEnter2D callback, I do a reflection over the collision normal to bounce the ball direction away from the wall like below
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log(other.gameObject.name, other.gameObject);
//when colliding with a surface, set the new direction based on the reflection of the direction over the normal
BallData.Direction = Vector2.Reflect(BallData.Direction.normalized, p.normal).normalized;
}
Is there a way to tell if the ball is passing through the platform then? How do I differentiate it from a normal surface collision?
Edit: Missed that it disables the collider, so I can check the collider.enabled.
Thanks!
Edit: Dang this doesn’t seem to work either the collider is coming back as enabled
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log(other.gameObject.name + ": " + other.collider.enabled, other.gameObject);
//one way platform effector colliders are disabled when going through them
if(other.collider.enabled != false)
{
//Only reflect if we're colliding with something that's enabled == true
//when colliding with a surface, set the new direction based on the reflection of the direction over the normal
BallData.Direction = Vector2.Reflect(BallData.Direction.normalized, other.contacts[0].normal).normalized;
}
}
Possible final edit?: Ahh I’m dumb it’s not the collider.enabled it’s collision.enabled.
Actual final edit for anyone who comes here later: The example below is the final version that does in fact work
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log(other.gameObject.name + ": " + other.collider.enabled, other.gameObject);
//one way platform effector colliders are disabled when going through them
if(other.enabled != false)
{
//Only reflect if we're colliding with something that's enabled == true
//when colliding with a surface, set the new direction based on the reflection of the direction over the normal
BallData.Direction = Vector2.Reflect(BallData.Direction.normalized, other.contacts[0].normal).normalized;
}
}