OnCollisionExit2D strange behaviour
Hello!
Edit: I managed to bypass the problem by making the triggerCollider2D wider than the actual platform for now. Would be glad, if another solution would be more clear since this feels kinda dirty and wrong.
I have a script for a 2D Two Way Platform (You can jump through from below and you can fall through it from the top by pressing the Vertical Axis Input. It is working fine most of the time. Problem is, sometimes the ExitCollision won´t recognize, so I continue falling through the lvl until I enter the collider on the platform again.
} void OnTriggerStay2D(Collider2D other)
{
if(other.gameObject.tag == "Player")
{
//other.gameObject.collider2D.isTrigger == true;
other.gameObject.GetComponent<BoxCollider2D>().isTrigger = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if(other.gameObject.tag == "Player")
{
//other.gameObject.collider2D.isTrigger == true;
other.gameObject.GetComponent<BoxCollider2D>().isTrigger = false;
//}else {
}
}
void OnCollisionStay2D(Collision2D other)
{
if(other.gameObject.tag == "Player" && Input.GetKeyDown (KeyCode.S))
{
other.gameObject.GetComponent<BoxCollider2D>().isTrigger = true;
}
}
void OnCollisionExit2D(Collision2D other)
{
if(other.gameObject.tag == "Player")
{
other.gameObject.GetComponent<BoxCollider2D>().isTrigger = false;
}
}
}
If you enter the collider and exit it before reaching the top of the platform, the script is attached to, you fall through the air. Is there any way to fix this? The Player BoxCollider2D stays on Trigger. I actually tried a lot with the Rigidbody of the Player. Nothing is working. How can I call the OnCollisionExit2D to be recognized, as soon as I leave the Trigger of this platform?
Your answer
Follow this Question
Related Questions
Collision not working 1 Answer
Physics 2D with tile collider corner problem 2 Answers
OnCollisionEnter2D is not being called 0 Answers
How to check if any/multiple 2D sprites neighbour/collide with eachother 0 Answers
OnTriggerEnter not being called 2 Answers