- Home /
RaycastHit.transform/collider
When I use RaycastHit.transform I get the grandparent of the collider the ray hit and when I use RaycastHit.collider I get the collider of the GO that my ray hit. Can someone explain why sometimes it works and sometimes it's something alse?
Answer by peter_field · Mar 19, 2014 at 12:02 PM
I think RaycastHit.transform looks for a rigidbody, so if the grandparent of the collider is the gameobject that has the rigidbody component on it then that is what will be returned. If you use RaycastHit.collider.transform you should get what you are after.
I just ran into the same issue. Its really badly explained in the Unity documentation and should probably be called RaycastHit.rigidbidy or something.
Hope this helps, Peter
Your answer
Follow this Question
Related Questions
Need Help with RayCast. No Vector? 1 Answer
Is there a way to detect if an object is being hit by a raycast? 2 Answers
Layermask doesn't seem to work 2 Answers
Raycast isnt working 1 Answer