UnitySteer - Steering components for UnityJul 8, 08:04 PM

Back in February I was working on a project for an article meant to appear in a GDC issue of Unity Developer. The article was intended to be a tutorial on pathfinding with several agents, and used Path for finding routes in the scene. Path, however, will only tell you how to best get from point A to point B, but will not maneuver your agent nor tell it what to do if it runs into other agents or stationary obstacles, so part of the article dealt with obstacle avoidance.

The tutorial got shelved when there were delays with Unity Developer and the issue was cancelled, but the work I’d done on the implementation got me thinking about the need for an obstacle avoidance and steering library for Unity, so in late April I started doing just that. A good couple months later and with some help from Emil Johansen, we’re now ready to release UnitySteer.

What does it do? UnitySteer contains a series of classes that help your game characters or vehicles maneuver around a scene: how to accelerate and for how long, how to turn depending on vehicle characteristics, how to act when avoiding obstacles or neighbors, how to keep a distance from other agents, or many other cases. Some of these behaviors are quite simple, but they can easily be combined to generate more complex vehicles.

It builds upon OpenSteer and OpenSteerDotNet, but we have ported it completely to Unity, removing redundant classes and calling Unity methods wherever it’s appropriate. It has also been expanded so that the vehicle classes have an option for receiving a Transform or Rigidbody on initialization, which the vehicles can then affect directly, and has undergone refactoring on areas such as pathways.

During the port we have also expanded on the original vehicle examples, generalizing them when possible, and have added other functionality such as:

  • Vehicle tethering
  • Radar prefab for a trigger-based proximity detector
  • Prioritization of steering behaviors based on weighing
  • Integration with AngryAnt’s Path

We currently have vehicles (along with their MonoBehaviours) for:

  • Flocking
  • Obstacle avoidance
  • Wandering
  • Pursuit
  • Chains of vehicles

All provide support for 2D and 3D movement.

You’ll notice that the base vehicles are C# classes and not MonoBehaviours. We did it this way for several reasons, including:

  • It allows us to use the vehicles to animate particles, which have neither a transform nor a rigidbody of their own.
  • Standalone classes are more lightweight, and we get to control when their Update methods are called, so we had the flexibility of doing multi-vehicle updates (you’ll see what I mean on the Lightning example).

Here are some webplayers of the library in action (they require the Unity 2.5.1 plugin):

You can also see some Quicktime videos:

During the coming days I’ll provide examples of the classes plus notes on how to use the library. It is still a work in progress, so things are bound to be changed or expanded as we go. For now, you can obtain the steering classes on github, as well as an example project using them. If you are unfamiliar with git you can obtain a copy of the project here, but I do recommend getting acquainted with git, since the repository will be updated more often.

UnitySteer is released under the MIT license.

by Ricardo J. Mendez

Comment

Commenting is closed for this article.