- Home /
Coroutine That was working previously not working in scene
Hey all Working on a game and i am using a rotation coroutine to rotate the model on its y axis. In a previous rendition of the project Im working on the rotation worked as intended however it no longer works and gets stuck at about 86 degrees and does not rotate the model at all. However from what i can tell the code for the information has not changed. Here is the current rendition:
public IEnumerator Rotattor(Quaternion current, Quaternion rotatetoo, GameObject robot) { print("here"); //float currenttime = 0; //float start = transform.rotation.y;
//float end = transform.rotation.y + rotatetoo.y;
while (true)
{
print("true");
// currenttime += Time.deltaTime;
robot.transform.rotation = Quaternion.Lerp(robot.transform.rotation, rotatetoo, Time.deltaTime / .4f);
float anglebetween = Quaternion.Angle(robot.transform.rotation, rotatetoo);
print(anglebetween);
if (anglebetween <= 5 && anglebetween >= -5)
{
print("FinalTrue");
robot.transform.rotation = rotatetoo;
yield break;
}
yield return null;
}
}
and this is the past version :
public IEnumerator Rotattor(Quaternion current, Quaternion rotatetoo, GameObject robot) { print("here"); //float currenttime = 0; //float start = transform.rotation.y;
//float end = transform.rotation.y + rotatetoo.y;
while (true)
{
print("true");
// currenttime += Time.deltaTime;
robot.transform.rotation = Quaternion.Lerp(robot.transform.rotation, rotatetoo, Time.deltaTime / .4f);
float anglebetween = Quaternion.Angle(robot.transform.rotation, rotatetoo);
print(anglebetween);
if (anglebetween <= 5 && anglebetween >= -5)
{
print("FinalTrue");
robot.transform.rotation = rotatetoo;
yield break;
}
yield return null;
}
}
This is the function that gets called for both: print("down"); velocity = downVel; StartCoroutine(animov.Rotattor(this.transform.rotation, Quaternion.Euler(0, 180, 0), gameObject)); // transform.rotation = Quaternion.Euler(0, 180, 0); anim.SetTrigger("180 turn"); // bulletScript.fire(bullet, shotDown, velocity); Down = false; attack = false; If these things do the same thing then any thoughts that would help with figuring out why the rotation gets stuck at 86 and some change for the rotation that would be awesome.
Your answer
