unity – How to rotate my enemy so it scans the area?


Hi I am new to unity so I am not super familiar with methods. I am trying to make my enemy rotate left then right double the amount that it rotated and back to the middle like this: +10 degree, -20 degree then +10 degree back to 0. I am trying transform.rotate however I belive I have a bad understanding of it and doing something wrong.

Here is the method:

IEnumerator LookAroundArea(GameObject self)
    {
        if (10 >= Random.Range(1, 500))
        {
            Debug.Log("it runs");
            
            self.transform.Rotate(new Vector3(0, 1, 0), 45 * Time.deltaTime * 45);
            yield return new WaitForSeconds(1.0f);
            self.transform.Rotate(new Vector3(0, -1, 0), 45 * Time.deltaTime * 90);            
            yield return new WaitForSeconds(2f);
            self.transform.Rotate(new Vector3(0, 1, 0), 45 * Time.deltaTime * 45);
            yield return new WaitForSeconds(1.0f);
        }
        dontrunagain = true;
    }
```



Source link

More To Explore

Share on facebook
Share on twitter
Share on linkedin
Share on email