- Home /
Detach from parent OnCollisionExit
Hi, I'm trying to detach an object from his parent when it's not colliding anymore (it's a rigidbody on a platform)
function OnCollisionStay (TheCollision : Collision) {
if(TheCollision.gameObject.tag == "Plateform"){
Debug.Log("NNNNNNNOOOOOOOOOO");
transform.parent = TheCollision.transform ;
}
}
function OnCollisionExit (TheCollision : Collision) {
if(TheCollision.gameObject.tag == "Plateform"){
Debug.Log("SSSSSSSSSSSSUUUUUU");
transform.parent = null;
}
}
Actually , the console is not even displaying SSSSUUUU when it's not colliding anymore , i've tried with OnCollisionEnter instead of OnCollisionStay , but it doesn't work at all and the object does not become the child of the platform when it collides with it
What can I do ???
Thanks for reading
Answer by Anykey · Sep 19, 2011 at 01:26 PM
function OnCollisionStay (hit : Collision) {
if(hit.gameObject.tag == "Plateform"){
transform.parent = TheCollision.transform ;
}
else{
transform.parent = null;
}
}
That should add you as a child under the platform and it should separate you from the platform when you are no longer on it.
Thank you so much OrangeLightning for answering this in another question
Answer by Anykey · Sep 16, 2011 at 07:04 PM
I've used a trigger as child of the platform instead of Collision with the platform itself and it works now
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Collider child object doesn't activate oncolissionEnter 1 Answer
Any help getting my trigger to fire? 0 Answers
Detach a child that has children 1 Answer