How would I convert the normal of a surface into a single float value that is the steepness of the ground?
Basically I want my controller to go into a “slide” state if I’m standing on a surface over 45 degrees.
I’ve looked around and am coming up blank.
I’ll keep looking, but I could really use a tip.
Thanks in advance.
Try Vector3.Angle:
float steepness = Vector3.Angle(hit.normal, Vector3.up);
2 Likes
Having not done this myself, and being garbage at maths, I believe a combination of the two would work?
So I suppose you could compare Vector3.up to the normal of a ray cast hit.
Edit: beaten to the punch
1 Like
Just check the y of the returned hit normal. It’s going to range from 1.0 (flat ground) down to zero the steeper the ground is.
It so just happens that the normal y is the cosine of the angle between the normal and the up vector, so you can convert it to he actual angle by passing it to Mathf.Acos().
3 Likes