Object rotation with angle constraints
Hello, I'm trying to make a turret self-rotate like it has AI, the issue is that I could get a random angle between a max and min value, however, I find it hard to use that value in order for the turret to rotate bit by bit from the actual angle to the new one. Here's what I've got so far:
float maxRot = -10f;
float minRot = -50f;
float angle;
void Update()
{
StartCoroutine(RotateTurret());
}
IEnumerator RotateTurret()
{
angle = Mathf.LerpAngle(minRot, maxRot, Time.time);
turret.transform.eulerAngles = new Vector3(0, 0, angle);
yield return new WaitForSeconds(3f);
}
This only rotates the object one time as minRot and maxRot are always the same.
Comment