Hopefully by now you all have skipped ahead of my painstakingly slow updates and just read all of gamedevtuts+'s series on agent movement. That way, you know, you might have actually gotten to the good part of the series with all the interesting movement types! We've already covered seeking, fleeing, and arriving behaviors and how they relate to the overarching steering principles. Now, esta semana, we cover the magnificent:
Agent Movement/Steering: Wandering Behaviors
Wandering is like the seeking and fleeing behaviors that we first studied because all that it does is it calculates a steering vector. In this case, the steering vector points to somewhere on the perimeter of a circle a certain distance away. This point is shifted every frame, so that when the calculated steering vector is added to the velocity, the steering vector is not so different from the actual velocity. This results in a fairly smooth side to side wandering motion.
The steering vector first needs a circle to be "drawn" mathematically a certain distance away from the agent in the direction that it is facing. The farther out that this distance is from the agent, the stronger the wandering force will be. The same goes for the radius of this circle.
Once the circle is constructed, the agent needs to determine where to point to. This is where the wander angle comes in. This value is persistent from frame to frame, and is slightly modified each time to always make the agent change directions. Using the wander angle and the circle, it's easy to use maths and stuff to find a new point to gravitate towards.
Again, the article does a good job explaining the exact mathematics, as does my Github repository if you're the type that likes to read code.
This method of creating wandering behavior is really nice. I know I say that about pretty much all of these methods so far, but I gotta say it:
It's super nice.
I love adding randomness to my AI's whenever possible/practical, and this code is a great way to get it done. The best part about it is that I can stack this wandering on top of other behaviors, like seeking or fleeing to create more complex behavior. It's brilliant.
Go ahead and run my code and you'll see what I mean. Mess around with the constants and see what sort of cool things you can get the agents to do. Maybe even try combining wandering with some of our other movements! You probably won't regret it.
No comments:
Post a Comment