Hey everyone in the script I tried making my ai ship turn while a variable is greater than zero but it never stops and spins way faster that if it was not in this while statement. Can someone take a look at how this part of the script is rotating the ship and show me how to make it rotate for a set time like I want. Please don’t just throw documentation at me I already looked at it… thats how I came up with this is all that documentation.
void Avoid()
{
if(dist < 20)
{
followTarget = false;
StartCoroutine (turn());
}
}
IEnumerator turn()
{
if(followTarget == false)
{
//wait the cooldown time in a loop
float turningTime = 5f;
while (turningTime > 0)
{
transform.Rotate(0, turnSpeed * Time.deltaTime, 0 * Time.deltaTime, Space.World); //and then turn the plane
//decrement turningTime
turningTime -= Time.deltaTime;
//let unity free until next frame
yield return null;
}
}
}