What would be the best way to do this?
What I want is my enemy AI to move from waypoint to waypoint and go around objects not through them. Also I want the enemy to stop at each waypoint and wait there for x amount of seconds then move on to the next. I also want other waypoints that are not part of the patrol but the enemy moves to when I do something. For example, if the enemy is in one room and I push a button, he will go to another room for x amount of time then go back to his patrol. I don't know how i should go about coding this. I was told to do a coroutine to pause the script so the enemy could wait but then would i not be able to have him go into his idle animation? Please help!
The unity navmesh is a good way to start. its fairly easy to setup and telling a navmesh agent a destination is enough to make him go there while avoiding obstacles. furthermore, it has callbacks for when it reached its target, which means you can then call your waits (Coroutinez) and then set a new one.
I know this is a lot, but you've asked a lot and what you want cannot be done with only just a little effort
Answer by Dylanpolis · Feb 21, 2017 at 12:56 AM
I understand fully that its alot. Thank you for the help! Ive tried to do this on my own and my script is just failing left and right.
Answer by ericbegue · Feb 22, 2017 at 02:39 PM
Behaviour Tree is a nice tool for writing complex AI. Once you can the hang of it, it will be easier to define AI than using couroutines and plain C#.
Have a look at Panda BT (www.pandabehaviour.com). It's a scripting framework based on Behaviour tree. The package contains several examples including patrol-chase-attack behaviours, which is close to what you want to do.
If you have any question about using this package or about Behaviour Tree in general, you are welcome on this forum thread.
Your answer
![](https://koobas.hobune.stream/wayback/20220612111550im_/https://answers.unity.com/themes/thub/images/avi.jpg)