- Home /
Get local normal of face
I raycast and hit a cube, its local rotation is 0,0,0 But its parent object is say 90,130 15 How do I get the local normal of the face I hit? so if I hit the top face it would give me (0,1,0) rather than where its normal is pointing relative to the world
Answer by Eno-Khaon · Sep 09, 2021 at 02:43 AM
One of the most straightforward ways should be to use Transform.InverseTransformPoint() to convert the world-normal to a local version. It's based on the total transformed state, so it factors in all applicable parent rotations, too.
Vector3 localNormal = cube.transform.InverseTransformPoint(cube.transform.position + [normal of RaycastHit on cube]);
Edit: As pointed out in the comment, a more appropriate solution is to just use InverseTransformVector() instead.
Vector3 localNormal = cube.transform.InverseTransformVector([normal of RaycastHit on cube]);
Thank you! Your code did not work first try, and it was way off. But then I figured I could try the "InverseTransformVector" Because the normal is a vector after all And pow! It worked! Thank you so much for pointing me in the right direction
Ah, you're absolutely right! I fixed my answer to make it properly context-sensitive, but InverseTransformVector() is definitely the more correct choice here.
Your answer
Follow this Question
Related Questions
jump at opposite angle of surface 2 Answers
How to snap a Prefab to the normal of an irregular mesh 1 Answer
hit.normal rotation problem, help please really confused 1 Answer
Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers
How do I measure how far from the normal a raycast is when hitting a surface? 0 Answers