Using Javascript at the moment since I don’t know how to store a rotation as a temporary variable yet (need to learn that) just going to post the code to start off.
if(Input.GetButton("Left"))
{
transform.rotation.y = -90;
}
When in-game, the rotation on the Y axis switches to 180 rather than -90, no matter what value I set for it. However,
if(Input.GetButton("Forward"))
{
transform.rotation.y = 0;
}
works with no problem. Any suggestions?
Try using transform.localEulerAngles instead
It is never a good idea to use the x, y, z, w values of a Quaternion directly unless you have a deep understanding of the math behind quaternions. Instead you can use the eulerAngles or use Quaternion functions (Rotate, RotateTowards etc)
Thanks, the rotation works properly now, but since the object has been rotated, when i move left he rotates to face left and moves forward since the direction is left in it’s viewpoint
Use .eulerAngles instead of .localEulerAngles
Turns out,
if(Input.GetButton("Left"))
{
transform.rotation = Quaternion.Euler(Vector3(0, -90, 0));
}
Has the same function as,
if(Input.GetButton("Left"))
{
transform.eulerAngles = Vector3(0, -90, 0);
}
Both work the same way, still transferred over to .eulerAngles.