- Home /
Character Controller change target direction in degree
Hey, whats the best way to change the target direction for a character controller? Currently I'm getting the forward vector relativ to the player along the x-z plane with
Vector3 forward = this.transform.TransformDirection(Vector3.forward);
Now I want to create a new Vector3 moveDirection which is showing 2° to the left/right. So a rotation around the players Y-Axis basically, but I need it as a direction to move.
Vector3 moveDirection = ??
After that, I will rotate the player to the new direction he's walking.
transform.rotation = Quaternion.LookRotation(moveDirection);
How to build the new moveDirection? I think its an easy thing, but I'm so confused atm... Thanks!
Answer by papfit · Apr 19, 2014 at 03:06 PM
Hey, as I thought, the solution was easy.
I created a Quaternion with a rotation of 2°
Quaternion twoDegreeLeft = Quaternion.AngleAxis(-2, Vector3.up);
and multiplied it with the original direction
transform.rotation = Quaternion.LookRotation(moveDirection) * twoDegreeLeft;
Your answer
Follow this Question
Related Questions
Problems caused by non-unique Euler angle solutions 1 Answer
How to set an exact Local angle. 0 Answers
Instantiating an object in front of the player 3 Answers
Camera lock on enemy 0 Answers
Camera Zoom from rotation. 0 Answers