Basically, this part of the script goes into the head of a character, I want the rotation to reset to its original position once the rotation of the head in the Y axis exceeds 90 degrees.
if (helping == true)
{
Head.transform.LookAt(PlayerControler.instance.transform.position);
if (Head.transform.rotation.y >= 90.0f || Head.transform.rotation.y <= -90.0f)
{
helping = false;
}
}
else
{
if (helping == false)
{
Head.transform.rotation = new Quaternion(0, 0, 0, 0);
}
}
1 Answer
1
transform.rotation returns a Quaternion. Quaternions are a way to express rotation in 3D space, but the x, y, z, and w of a Quaternion does not correspond to rotation around the x, y, and z axis.
You can try transform.rotation.eulerAngles to get a representation of the rotation about the x, y, and z axis. This may return some unexpected values, so I encourage you to use Debug.Log to print out this value so that you can see how it varies as the character is rotated.
Also, to reset rotation, you should transform.rotation equal to Quaternion.identity.
An "zero" rotation is not Quaternion(0, 0, 0, 0). It is Quaternion(0, 0, 0, 1). This is why you shouldn't create Quaternions manually using "new", because they're not straightforward. Instead, you use =Quaternion.Identity or =Quaternion.Euler(0,0,0).
– ArachnidAnimal