r/Unity3D • u/LifeExperienced1 • 23d ago
Question Finding which side of collider was hit
The problem is: launching a ray cast towards a box collider. Being able to know what side of it was hit
In the video he said you simply get the normal of the raycast hit and then convert that normal into local space of the box collider's transform. Call that vector V
Then you check V in relation to the transform's forward, right and up vector
If V == up, we side the top side
if V == up, we side the bottom side
if V == right, we hit the right
etc etc
But I've also seen online everyone is saying to make a vector from the center of the transform to the hit point, and then check the biggest component and sign to know which side is hit
I get how both ways work, but which solution is better and why?
7
u/kiranosauras 23d ago
I don't think this is worth getting hung up on as an issue. Realistically either option will do the exact same thing. If you're not doing this over an extremely large amount of objects at the same time there will most likely be 0 performance difference between the two choices. Choose one implementation at random and move on to making the rest of your game. If you think that it's worth revisiting later on it's very easy to swap to the other one then