Hey Guy’s!
I’ve got a little problem and I have no idea what I did wrong.
I’m making a 2D game and at the moment I’m trying to implement that the player is rotating 90 Quaternions. Now that itself is not a problem. The problem is stopping at the right time. It should stop when rotation.y gets lower than 270 Quaternions, but it just continues and stops the rotation when it is just over 0.1 Quaternion…
There’s no problem with rotating it to 0.0 (so that shifted = false again).
I honestly have no idea where my mistake is, so I would like to ask if you can find it.
The script is written in C#
Here’s the code:
float rotationSpeed = Time.deltaTime * 50.0f;
if (Input.GetButtonDown ("Shift"))
{
shifting = true;
}
if (shifting == true)
{
if (shifted == false)
{
if (player.transform.rotation.y > 270.0f || player.transform.rotation.y < 0.1f)
{
player.transform.Rotate (new Vector3 (0,-rotationSpeed, 0));
}
else
{
Debug.Log(player.transform.rotation.y);
player.transform.rotation = Quaternion.Euler (new Vector3 (player.transform.rotation.x, 270.0f, player.transform.rotation.z));
shifted = true;
shifting = false;
}
}
else
{
if (player.transform.rotation.y > 0.0f)
{
player.transform.Rotate (new Vector3 (0, rotationSpeed, 0));
}
else
{
player.transform.rotation = Quaternion.Euler (new Vector3 (player.transform.rotation.x, 0.0f, player.transform.rotation.z));
shifted = false;
shifting = false;
}
}
}
I hope you can find the mistake and help me.
Thanks in advance and have a nice day ^^