My most recent assignment for the Game Design class I’m taking is to implement some behavioral animation steering behaviors. The task was to implement steering behaviors such as: seek, flee, separation, avoid, follow the leader, and flocking.
We were provided a framework featuring Lenguin characters
and a menu like this:
and entry points to call a C++ dll that would return force and torque vectors given agent properties and world data. It was a really interesting exercise, and it’s always tricky and fun implementing algorithms. One of the more difficult ones was the avoid behavior, which allows agents to go around obstacles
This is done by detecting a collision with an object, and adding a tangential velocity to the agent’s current velocity, allowing it to walk around an object, hugging its radius. This was both an exercise in implementing algorithms and using Unity’s native plugin capability. Although the Framework was provided for Visual Studio, it was fairly straightforward to port it to XCode, and Unity allows OSX users to compile native plugins into Bundles.
One of the weirdest things I found is when I went to port my XCode c++ back to Visual Studio, I was getting crazy velocities back. It took me a couple hours to discover that the default constructors for the vec3 structures, which store the values in a float array, did not initialize the array values. It’s odd because this worked fine on XCode/OSX, and I’m wondering if XCode did something special with the array values, like initialize them to 0.
Here’s a short video of the Lenguins in action:
Here are links to executables if you’re interesting in trying yourself. Use ctrl-click to move the target, and click on the Behavior menu to change the behavior.