- Home /
Why dont collision detection works on child object?
Hi, I have a Enemy which is from many parts. It looks like cube, and each wall is a separeta object, that is a child of a empty gameObject witch rigidbody, because i want it to response to physics. BUT. I have a script like this
var TextureState1 : Texture2D; var TextureState2 : Texture2D; var TextureState3 : Texture2D;
var hits : int = 0;
function OnCollisionEnter(other : Collision) { if(other.gameObject.tag == "explodeWall") { other.gameObject.renderer.material.mainTexture = TextureState1; } }
so, what it should do? I have a ball prefab i can shoot, and i have this script attached to the ball. When i shoot a ball to a object with tag explodeWall it does what it should. It changes the material. But when its a child object, even the SAME but its just a child, this dont works :(.
Ok, now i know where is the problem. It dont works when it has a parent rigidbody. So? :(
David.
Answer by microp · May 25, 2011 at 05:11 PM
It seems that's how Unity works. When something collides with a compound rigidbody, OnCollision*() are called only on the parent, even if a child's rigidbody collided first. You can work your way around this by putting a script on your empty GameObject that handles OnCollisionEnter() and forwards the event to your children.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
if (GameObject.Find("name").renderer.material.name == "mat_name") {do smth..} 3 Answers
How to change color to every specific material in a child of a group..? 1 Answer
Move player after colliding with trigger? 1 Answer
enable components from multiple objects 0 Answers