Home

Awesome

Context Steering

This is a Unity package to add context steering to a wide range of projects quickly and easily.
The inspiration for this project was due to a Devlog by Game Endeavor and a subsequent read of the companion article Context Steering Behavior-Driven Steering at the Macro Scale by Andrew Fray.

Contents

<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>

What is context steering?

It is not a replacement for pathfinding. However it is relatively easy to use it in conjunction with a pathfinding system (like the Unity NavMesh) - an example of this is included in the Demo scene.

Context steering involves defining multiple behaviours on an entity (aka. GameObject), combining them, and producing a single output vector that represents a direction that is statistically good for the entity to move in. This allows us to define many discrete simplistic behaviours that when combined can produce seemingly complex movement.


Getting Started

Check out the Demo scene

First things first, a demo scene has been included that displays some basic usage of this tool. When importing the package into your project you should see a tick box to include the sample scene. The scene is stored at: Samples/DemoScene/Scenes/DemoScene.unity

This scene provides some examples showing how you might use this package. Cyan cylinders represent agents which are using steering behaviours, Orange spheres are projectiles or obstacles to avoid, and Mauve objects represent targets the agents will try to reach.

Taking a look at an agent (depicted below) there are a few scripts to pay particular attention to:

BasicAgent

<small>Also note the PlanarMovement demo script, when using this package you would likely create a similar script yourself to decide how to use the output vector in your game.</small>

Each demo includes some basic metrics; total collisions, collisions in the last n seconds, average collisions per n seconds, and number of goals achieved (contact with correct Mauve objects). Play with the PlanarController, Behaviour, and Mask parameters to see how they each effect agents movement, collisions, and goals.

The Map Debugger when enabled can help provide some visual context for what each behaviour is doing. Note that the length of the lines in this visualisation are normalised to the Map Size so they are not a true representation of the internal data.


Basic usage

Controllers

This package is designed so that once you have configured the behaviours on your agent you can use the output vector (or direction) however you wish.

The output vector is provided by a controller component, currently the only controller that has been implemented is the SelfSchedulingPlanarController, but if you wish you can extend the PlanarSteeringController class and implement your own custom planar controller.

See the PlanarMovement demo script for an example of interacting with a controller.

Controller Parameters

Context Map Visualised

SelfSchedulingPlanarController Parameters

Behaviours

Inclued in this package are 4 Behaviour classes; DotToTag, DotToTransform, DotToLayer, DotToNavMesh. Each behaviour differs only in how an array of Vector3 positions is generated each time the controller "thinks", adding new planar behaviours is as simple as overriding the GetPositionVectors method.

Commmon Behaviour Parameters

Masks

There are 3 Mask classes; DotToTagMask, DotToTransformMask, and DotToLayerMask. Masks are very similar to behaviours but instead of attracting or repulsing they block (or mask out) a direction entirely. They can be useful in conjunction with a scale on distance Repulse behaviours to create a lower band on distance to an object (like a wall). Masks do not guarentee that an agent will not move into something masked out, but they do reduce the probability.

Mask Parameters

See behaviour Parameters


Installation

Either download the latest Release .zip file, or change to the UPM branch and hit the green Code button and select Download ZIP.

  1. Open the Package Manager (under Window -> Package Manager).

    OpenPackage

  2. Click the "+" icon, and select "Add package from disk...".

    PlusIcon

  3. Browse to the directory this package is installed at and open the package.json file.

    SelectPackageJSON

Alternatively you can add the package using the Git URL (Code -> HTTPS).