- Home /
Question by
Bioinformatizer · Feb 09, 2016 at 02:51 AM ·
platformerplatform
What is the best way to fall back through a PlatformEffector2D?
First : I DO want the character to fall through the platform.
There is a PlatformEffector2D in my scene currently tagged "Wall" that the character of the game can pass through the bottom of. When you hold the vertical axis down to get -1 ( variable 'v' in this case) the player can pass back through the platform the other way. This is currently done by turning off the colliders for the character and turning them back on. The trigger collider on the character 'groundSpace' is used to detect the collisions for this using OnTriggerStay2D and OnTriggerExit2D coded below.
Is there a better / more efficient way of doing this?
void OnTriggerStay2D(Collider2D other)
{
if (v == -1 && !fallingThrough)
{
if (other.CompareTag("Wall"))
{
fallingThrough = true;
foreach (Collider2D col in gameObject.GetComponents<Collider2D>())
{
col.isTrigger = true;
}
}
}
}
public void OnTriggerExit2D(Collider2D other)
{
if (fallingThrough && other.CompareTag("Wall"))
{
fallingThrough = false;
foreach (Collider2D col in gameObject.GetComponents<Collider2D>())
{
if (col != groundSpace)
col.isTrigger = false;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612063528im_/https://answers.unity.com/themes/thub/images/avi.jpg)