# Angle/rotate rigidbody player

my player is a rigidbody, no CC. I wanted to rotate the player according when hes on a slide/uneven objects.

how would i do this? i can raycast, but whats this about normal? i dont understand what it is

before I explain what a normal is, I will explain what a Vector3 is. It is 3 numbers which denote a place in space. The cool thing about a vector is that it can tell you location, distance and direction. So if you think of a regular vector3, lets say 10,10,10 it is at world space 10,10,10. Easy enough. If you then get its relation to another vector, (say, 1,2,3) you would do a subtraction to get that vector.

(target - current) = offset.
(10,10,10) - (1,2,3) == (9,8,7)

Now with the magnitude property of a Vector3 you get the length (or distance) between the two. (this calculation is nothing but the absolute values of each added together and divided by 3, so 9+8+7 = 24 / 3 = 8.

Now a normal is nothing but that same piece of math, but it forces the length to 1. The neat thing about this is that you can then specify that length by getting the normal and multiplying that by a length you supply and the age old principle of 1 * n = n kicks in. (we can use this all over the place)

OK, now onto your problem. You have a hit point that comes from either physics or a raycast. Lets assume that your slide is tagged Slide so that we know that we are supposed to rotate the player. (wouldnt make much sense to rotate everywhere) And we get a normal which vaguely points upward, but more in the direction of the slide.

Now, lets use the power of normals. Vector3.up is world up, it is (0,0,1) (Length of 1… ) and the normal we get. We can use a Vector3.Dot to tell is if the normal is closely pointing upwards. So Vector3.Dot(normal, Vector3.up) should be greater than 0.5, (1 is the same direction, -1 is the opposite direction) if it is, then we want to get the point of the normal. (hit.point + hit.normal) and use Transform.LookAt() to look at the point.

If you want the character to not look down when it does this, simply make the look at point’s Y the same as the character’s Y.