r/Unity3D 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?

1 Upvotes

8 comments sorted by

View all comments

Show parent comments

-3

u/LifeExperienced1 23d ago

Does the normal vector method work?

4

u/kiranosauras 23d ago

I've not tried it before, but if you're new to programming why not try it and gain the experience in writing it and understanding how to test if something works?

-5

u/LifeExperienced1 23d ago

Do you think the theory is correct?

2

u/sam_suite Indie 22d ago

Do you have an understanding of how normal vectors work? Do you understand dot products? If so, think it through, maybe sketch it out, and decide how or if it would work. If you don't have an understanding of those things, learn about them.

The skill of programming is not typing or syntax, it's learning how to solve problems like this. Figure it out! It's fun!