I’m basically trying to create Doodle Jump in Unity, but I need help with part of it. In the game, you can pass through blocks when you’re below them, but jump when you’re above it. My method for doing this is to disable collision when it detects the player is below the block, but the issue is that with OnCollisionEnter, it detects the collision when it happens. I need to be able to disable collision before the collision actually happens. Is there any way to do this?
private void OnCollisionEnter2D(Collision2D col)
{
Vector3 contactPoint = col.contacts[0].point;
Vector3 center = col.collider.bounds.center;
if (contactPoint.y > center.y)
{
rb.AddForce(new Vector2(0, 6), ForceMode2D.Impulse);
}
else
{
GetComponent<Collider2D>().enabled = false;
}
}
private void OnCollisionExit2D(Collision2D col)
{
GetComponent<Collider2D>().enabled = true;
}