|
So I set up a simple waypoint script, where my AI patrols several waypoints, and when it reaches a waypoint, it rotates towards and moves to the next waypoint. All I want to do is make it so that when the AI gets to a waypoint, he pauses for a moment, and THEN rotates and moves to the next waypoint. I've tried a couple things, like setting up timers and using WaitForSeconds, but I can't figure it out. Anyway, here is my script in its current state:
I've been trying to do the pause inside of if(waypointDistance <= waypointStopRange), because that is when he has reached currentWaypoint, and when currentWaypoint is incremented to the next. I cannot for the life of me figure out how to get him to stop moving for a few moments there. If I use yield WaitForSeconds(), he will just get stuck there indefinitely.
(comments are locked)
|
|
I would rather than calling the Patrol function from update, call it from a start function similar how the FPS tutorial does it. Then yield after every check and once the character reaches his waypoint, then you can use WaitForSeconds() without any issue.
The script above looks very similar to the one you wrote so there would not be much to change. I find that state based behavior usually works better from system similar to above because then each state just calls the next instead of a central Update trying to figure it out. Why is it that yield WaitForSeconds would behave differently in Start() versus Update()? Also, I removed it because it wasn't relevant to my question, but inside patrol() I also do my checks for distance to the player, and run the attack function if hes within range. Would that be effected if I moved Patrol() to Start()?
Apr 28 '10 at 02:48 PM
PrimeDerektive
Nice! Nevermind I figured it out. I can't say I fully understand how coroutines work, but at least now I can use them :)
Apr 28 '10 at 06:52 PM
PrimeDerektive
(comments are locked)
|
