I’m currently making a own third person script and need now to adjust an angle so, that the Y-Axis points always up(world-space upvector). But I don’t know how to make that. Which function could do that?
1 Answer
1Make a vector point up? Vector3( 0, 1, 0 ) or Vector3.up.
What I think you mean to ask is how do you make a Quaternion (rotation) always have the local y-axis point up (allign with the global y-axis).
The answer is, use Quaterion.LookRotation:
transform.rotation = Quaternion.LookRotation( directionYouWantHimToFace, Vector3.up )
Where directionYouWantHimToFace is the Vector3 with y=0 and x and z pointing in the direction you want him to look. You can even leave out the Vector3.up part, since it’s implicit. I only included it for clearness.