Question by
LinkUpGames · Nov 29, 2016 at 08:16 AM ·
c#vector3quaternion
Look rotation viewing vector is zero
Hi there, this question has been asked numerous times as I found by Googling the solution. However the solution everyone gave was to place the Quaternion within an if statement declaring
if(NextDir != Vector3.zero){}
The problem being that my Quaternion rotation is already inside that if statement and it still gives me the "error"
Here is my code I'm not sure exactly where the issue lies:
CharacterController controller = GetComponent<CharacterController>();
NextDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
Quaternion wantedRotation = Quaternion.LookRotation(NextDir);
if (NextDir != Vector3.zero)
{
this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, wantedRotation, rotateSpeed * Time.deltaTime);
}
NextDir *= speed;
controller.Move(NextDir * Time.deltaTime);
Comment
Best Answer
Answer by slavo · Nov 29, 2016 at 01:00 PM
Hi you are calculating LookRotation before sanity check.
CharacterController controller = GetComponent<CharacterController>();
NextDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if (NextDir != Vector3.zero)
{
// Do not calculate rotation if dir is zero
Quaternion wantedRotation = Quaternion.LookRotation(NextDir);
this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, wantedRotation, rotateSpeed * Time.deltaTime);
}
NextDir *= speed;
controller.Move(NextDir * Time.deltaTime);
This should remove your warning.
Oh wow I should've noticed that! Thank you very much!
Your answer
Follow this Question
Related Questions
Look Rotation Viewing Vector is Zero 0 Answers
Grappling hook physics script error 0 Answers
Rotation Perpendicular to Line Segment 1 Answer
How to get local angle of travel 0 Answers