- Home /
Hit Angle Of Ray to Surface?
Ive been looking around but i have a weakness with angles in 3d space. How would i calculate the angle of a raycasthit to the surface it. I assume its utilizing the information from "hit" in the raycast, perhaps the normal data, but i dont quite know how to get it.
ahh perhaps i can use Vector3.Angle(ray direction, normal);
Answer by Michael CMS · Nov 01, 2012 at 11:22 PM
What you want is the dot product between the normal and your ray direction.
The dot product between two directions equals the cosine of the angle :
http://en.wikipedia.org/wiki/Dot_product
All you need to do is to take the direction of the ray and make a dot product with the normal from the raycast hit.
Ray r;
RaycastHit hit;
...
float cosine = Vector3.Dot(r.direction,hit.normal);
float cosineDegrees = Mathf.Acos(cosine);
actually the Angle function worked fine, it spits out a value going from 180 to 90 as steepness increases.
Your answer
![](https://koobas.hobune.stream/wayback/20220613083051im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with casting and drawing multiple raycast along an angle 0 Answers
Particle Instantiation problem. 0 Answers
Click&Drag Misterious Disappearing! 1 Answer
How I can know surface angle? 2 Answers
Is object at least partly visible? 1 Answer