- Home /
onCollisionExit2d problem, character doesn't get deparented
Hello everyone, I'm making a simple 2d platform game, but I'm having troubles with moving platforms. When character jumps on the moving platform I change the character parent to platform, and actually works fine. The problem is I can't found the correct way to deparent the character when it leaves the platform. This is the code I have in the platform:
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Heroe") {
other.transform.SetParent (transform, true);
}
}
private void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.tag == "Heroe" ) {
other.transform.SetParent (null, true);
}
}
The worst thing I can't understand is this: When I write the onCollisionEnter2D alone (whitout implementing OnCollisionExit2D), the character get attached to the platform succesfully. But when I implement the OnCollisionExit2D, the character doesn't get attached anymore... like neither of the methods (onCollisionEnter2D and onColiisionExit2d) were working. Any idea where's my mistake?? Thanks a lot!
Your answer
Follow this Question
Related Questions
OnCollisionExt not working/ Alternate collision detection 1 Answer
How can I make my truck drive on terrain and on bridge 1 Answer
Delayed Collisions Bug (includes video demonstration) 1 Answer
Boo & Collision 1 Answer
Why is my OnCollisionEnter function working for enemies and not my player? 1 Answer