Table of Contents

First steps

The steer behaviours AI is integrated with MonkeyBrains so before start coding be sure that you have checked the monkey brains documentation

Be sure to create a reference to MonkeyBrains from your project.

Finally, do not forget to import the package.


Avaliable behaviours:

All the behaviours extend from the AbstractSteeringBehavior class.

Adding a steer behaviour

Create instances from the steer behaviour classes, They are located in the package.

If we want to add more than one steer behaviour, we need to create a container:

If you add more than one steer behaviour to a SimpleMainBehaviour it will cause problems in the rotation of the agents.

Container Purpose
CompoundSteeringBehaviour Contains and merges several AbstractSteeringBehaviour instances
BalancedCompoundSteeringBehaviour Each force generated inside this container is reduced in relation with a proportion factor: "Partial Force" / "Total container force"

Once we know which container fits better for our agent, We create a new instance and add all the behaviours that we need:

SimpleMainBehaviour mainBehaviour = new SimpleMainBehaviour(myAgent);
    CompoundSteeringBehaviour steer = new CompoundSteeringBehaviour(myAgent);
    //BalancedCompoundSteeringBehaviour steer = new BalancedCompoundSteeringBehaviour(myAgent);

Note that you can have nested containers, like is shown in the following example:

SimpleMainBehaviour mainBehaviour = new SimpleMainBehaviour(myAgent);
    CompoundSteeringBehaviour steer = new CompoundSteeringBehaviour(myAgent);
        BalancedCompoundSteeringBehaviour nestedSteer = new BalancedCompoundSteeringBehaviour(myAgent);

Prioritizing behaviours

You can assign priority layers: The steering controller first checks the higher layer to see if all the behaviours returns a value higher than minLengthToInvalidSteer, if so it uses that layer. Otherwise, it moves on to the second layer, and so on.

To assign priority layers add behaviours with the following function:

  addSteerBehaviour (AbstractSteeringBehaviour behaviour, int priority, float minLengthToInvalidSteer)

To optimize the process speed add the behaviours with the lowest priority first.

The layer and the min length to consider the behaviour invalid are 0 by default.

Setting up forces

If a behaviour extends from the AbstractStrengthSteeringBehaviour class, you can manage how the produced forces will work.

Use setupStrengthControl(float scalar) to increase/decrease the steer force produced by a behaviour or setupStrengthControl(Plane plane) If you want to work with 2D behaviours.


    Plane horizontalPlane = new Plane(new Vector3f(0,1,0), 0);
    steerBehaviour1.setupStrengthControl(0.5f); //Force reduced a 50%
    steerBehaviour2.setupStrengthControl(horizontalPlane); //Force contained in the XZ plane
    steerContainer.setupStrengthControl(horizontalPlane, 2f); //Contained in the XZ plane and increased a 100%

Implementing your own steer behaviour

To benefit from all the features, you have to create a new class that extends from AbstractStrengthSteeringBehaviour.

The responsible for the agent's acceleration is the vector returned in the calculateFullSteering() method:

    protected Vector3f calculateFullSteering()
        Vector3f steerForce = Vector3f.ZERO;
        return steerForce;

In addition, you can change a brake factor which will reduce the resultant velocity for the agent:

    protected Vector3f calculateFullSteering()
        this.setBrakingFactor(0.5f); //The agent's velocity will be reduced a 50%
        return Vector3f.ZERO;

The braking force must be a float contained in the [0,1] interval

0 means the maximum braking force and 1 No braking force

Strict arguments

To ensure that the behaviour will work as you had planned it to work It's recommended to create your own IllegalArgumentException class. To do this, extend from Furthermore, It will help users to recognise better which is the origin of any problem.


    /** @see IllegalBehaviour */
    public static class customRuntimeException extends IllegalBehaviour {
        private customRuntimeException(String msg) { super(msg); }
    public steerBehaviourConstructor(Agent agent, int value, Spatial spatial) {
        super(agent, spatial);
        if(value > 5) throw new customRuntimeException ("Value must be lower than 5");
        this.value = value;

Copyright (c) 2014, Jesús Martín Berlanga. All rights reserved.

Creative Commons License
Licensed under a Creative Commons Attribution 3.0 Unported License.