UnitySteer – Steering components for Unity


UPDATE: I’ve done multiple UnitySteer releases during the past few years. Click here for the latest news as this article is now outdated.

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 canceled, 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.

  1. Heinz

    Do you know that many classes are not compiled with unity?

    Namespace are just fine, but with code compiled by Unity, the class name must match the filename. Same goes with Generic classes.

    So generally you have to also declare a shell class outside of the namespace that matches the filename.

    Geetings Heinz

  2. Trevor Coates
    Trevor Coates07-13-2009

    Hi Ricardo,

    I am trying to get the example project working and it can’t find all of the scripts that are present in the assets folder.

    I have Unity 2.5.1 I updated the mono code when I installed Path. I am running OSX 10.5.7.

    I believe I have missed something simple?


  3. daodao

    Great work! I just wonder if it works on unity iphone?

    • Ricardo J. Méndez
      Ricardo J. Méndez01-11-2011

      It does, but of course you’ll have to scale the number of agents to deal with the reduced platform power, and might not want to rely as much on the physics engine for proximity detection.

  4. Pedro

    I would use for A.I. UnitySteer a car but not how. I built a city with Unity, I created a network of roads by A * Pathfinding and my idea is that cars can detect potential obstacles (other cars, traffic signs, pedestrians, etc..), but not how to apply my UnitySteer project.
    I searched for tutorials on its operation and applications, but I still know how to apply it on my project, to see if I could help.


  5. Ricard Borras
    Ricard Borras09-19-2011


    I have found a bug in Steer for tether behauviour when it combines with Wander and Neighbour avoidance behaviours. When attached object reaches the maximum distance and tether starts its force, the object gets stuck, with no movement. This is caused by small numbers in velocities, which are zeroed by blendIntoAccumulator in AutonomousVehicle. I have resolved by applied a threshold to avoid applying tether force when the vehicle has low velocity, in CalculateForce from tether:

    if (distance > _maximumDistance & Vehicle.Speed > _speedThresholdToApply )
    steering = difference – Vehicle.Velocity;

    Best regards and excellent job!

    • Ricardo J. Méndez
      Ricardo J. Méndez09-20-2011

      Hello Ricard,

      Thanks for the pointer. I believe another change I did on the experimental branch has a similar effect, but it was a while ago so I’ll verify it. Cheers!

  6. Isaac R.
    Isaac R.11-16-2011

    Hello. I’m new to this UnitySteering, and thought it’d be nice to ask if there is a tutorial anywhere for UnitySteer.

    • Ricardo J. Méndez
      Ricardo J. Méndez11-18-2011

      Hello Isaac,

      I’m afraid there are no recent tutorials, as I have been swamped with our game. Depend on your use case (for instance, if you’re using bipeds) you may want to wait for the RVO/PLE implementation in Unity 3.5.

  7. Greg Quinn
    Greg Quinn04-12-2014

    If anybody has a problem running UnitySteer on an iPad or iPhone, and you get the dreaded…

    Rethrow as TypeInitializationException in Vector3Pathway.AddPoint

    You need to replace any instance of the .First() and .Last() methods in Vector3Pathway.cs
    with an array reference.

    So change

    _points.First() to _points[0]
    _points.Last() to _points[_points.Count – 1]

    • Ricardo J. Méndez
      Ricardo J. Méndez04-12-2014

      Hi Greg,

      I haven’t deployed the latest versions to iOS, but Unity’s AOT can be fickle so it doesn’t surprise me that it barfs on Linq functions. Do you get any problems when on the call to FirstOrDefault()?

      Please file an issue report on github.


Leave a Reply