- Home /
How to find colider steepness?
In my game i need to find current steepness of terrain. I was thinking to raycasting from 1 unit at front of capsulcoliders midle point downward and get hitpoint. Then i would compare hitpoint with capsulecoliders bottom and get degrees. Are my thinking right? Or there are something better solution to get it done?
Answer by tanoshimi · Aug 18, 2016 at 07:23 PM
The normal
property of the raycast result already gives you the normal of the surface it hit: https://docs.unity3d.com/ScriptReference/RaycastHit-normal.html
And if you want the actual angle you would simply calculate the dot product between the world up vector and the hit normal. This gives you the "cos(alpha)" of the surface angle. To get the angle just use $$anonymous$$athf.Acos to get back the angle in radians. $$anonymous$$ultiply the result by $$anonymous$$athf.Rad2Deg and you get degree:
var angleInDeg = $$anonymous$$athf.Acos(Vector3.Dot(Vector3.up, normal)) * $$anonymous$$athf.Rad2Deg;
Your answer
![](https://koobas.hobune.stream/wayback/20220612091103im_/https://answers.unity.com/themes/thub/images/avi.jpg)