- Home /
How to raycast a child collider of a parent rigidbody
I am trying to Raycast to a child of my enemy GameObject. enemy has a rigidbody used for movement and no colliders. I want to shoot a bullet at the enemy via raycast but instead of hitting the parent hit the child objects ie his head. for some reason even using a layermask i cant hit the children only the parent.
Answer by Pysassin · Feb 04, 2013 at 10:44 PM
No they dont as it screws up the movement. I did discover though that even though the hit information refers to the parent you can get the collider you hits transform which would be the child. So instead of hit.transform id use hit.collider.transform.
Answer by hoy_smallfry · Feb 04, 2013 at 09:35 PM
Do the children have rigid bodies? If they do not have rigid bodies, then the colliders in the children are all treated as if they are part of the parent.
This is a engine feature so that it is possible to make objects with irregular or concave geometry (Read the section labeled "Compound Colliders" halfway through): http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html
Your answer
Follow this Question
Related Questions
Adding rigidbody engages children colliders? 2 Answers
How to rotate an object 360 degrees around a sphere with collisions? 0 Answers
How to limit a ray to go downwards to infinity, how can I make it down only 1 float. 0 Answers
Raycast Problem. CharacterJoint/Rigibodies 1 Answer
Raycast doesn't register Rigidbody 1 Answer