Hey guys,
I am trying to create a Smash Bros. Style game where a player can jump on platforms from below and drop back down if he decides to no longer stand on the Plattform. For that I’d love to have a mechanic to drop a player from a platform if he holds ta certain key down.
I am however wondering how to do this, without throwing other players of the platform as well. I am currently using Physics2D.IgnoreCollision and slapping my player and the platform as well as the true flag in there, but I don’t know how to enable it once the player has dropped through. I don’t want to time it since the game is very fast paced. I would love to check for if the player is still touching the platform and if that is not true, I’d love to enable the collision again. Problem is, when I ignore collision, I obviously won’t get any collision to check if the player is still near the platform.
I hope someone can help me with this.
Here’s a bit of code I use to make the current logic happen:
Collider2D currentPlatform;
Collider2D playerCollider;
private bool dropThroughPlatform;
...
public void DropThroughPlatform(InputAction.CallbackContext context)
{
if (currentPlatform != null)
{
Debug.Log("Dropping");
Physics2D.IgnoreCollision(playerCollider, currentPlatform, true);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("Registered Plattform");
currentPlatform = collision.collider;
}