- Home /
How to detect which side is the raycast hitting?
Hi everyone, I just want to ask on how can I have object detect which side of it is being detected by the raycast. I want to have the player to initiate different animations depending on which side the object is being interacted.
Answer by sieunpark77 · Apr 29, 2020 at 12:55 PM
My guess you could attatch seperate colliders in each side to achieve it simply.
I dont really understand your exact situation but if it is simple, you can just compare the x, y coordinates values.
Answer by Acegikmo · Apr 29, 2020 at 01:21 PM
transform the coordinate into local space of the object being hit, and then check if x is greater than or less than 0, so see what side it hit!
Vector3 hitPtLocal = hitObject.transform.InverseTransformPoint( hit.point ); // world to local
if( hitPtLocal.x > 0 )
// right side
else
// left side
Your answer
Follow this Question
Related Questions
Lay a Sphere on a Point 3 Answers
Custom Collision Detection 4 Answers
Collision Detection If Raycast Source Is inside A Collider? 4 Answers
Raycast bullet collision problem 1 Answer
Help with a field of sight 3 Answers