Tweaking the Auto-Pilot

When a vehicle’s auto-pilot has two or more steering behaviours switched on they sometimes conflict giving unattractive movement. There are a number of ways to tweak the auto-pilot to improve this.

Combined Steering Force Calculator

The library supports two methods for calculating the overall steering force from multiple behaviours (described in this guide) the default method is Weighted Truncated Running Sum with Prioritisation and generally this is the better of the two, but you could try the Weighted Truncated Sum method. To change the calculation method for an agent use -

agent.AP().calculateMethod(WEIGHTED);
// or to set it back to the default
agent.AP().calculateMethod(WEIGHTED_PRIORITIZED);

On its own changing the calculation method is probably not enough.

Steering Behaviour Weightings

Every steering behaviour has its own weighting factor that can be tweaked, the library default values provides a reasonable balance but they can be changed with

agent.AP().behaviourWeight(weight);

replacing behaviour with the name of the behaviour and weight the new weighting value. This works well with both calculation methods.

These are the initial weightings used by the library -

Behaviour Weighting
Wall avoidance 220.0
Obstacle avoidance 80.0
Evade 1.0
Flee 20.0
Flocking 1.0
Separation 1.0
Alignment 4.0
Cohesion 15.0
Seek 20.0
Arrive 20.0
Wander 5.0
Pursuit 100.0
Offset pursuit 10.0
Interpose 10.0
Hide 10.0
Path following 20.0

Maximum Force

When a vehicle is created it is possible to set the maximum force that can be applied to the agent by the auto-pilot. By carefully adjusting this and using the default combined force calculation method it is possible to reduce the effects of lower priority behaviours.

The difficulty is in knowing what value to use; here the library can help by providing information about the forces calculated for an agent. To do that for a particular agent use

agent.forceRecorderOn();

then allow the program to execute long enough for it to gather some data, then print the data out with

agent.printForceData();
// if you are logging multiple agents then use this to show all results.
world.printForceData();

You might trigger the output with a key typed event

This picture shows the output from the sketch in the previous guide.

forces calculated from previous guide

When collecting the data zero forces are ignored and the reported values have the weighting applied. Technically the standard deviation has no real significance since the distribution is not normal (in the statistical sense) but it can give a sense of the variability of the calculated force. For instance, in this example, the wall avoidance force is much more variable than the wander force even though its average magnitude is much smaller. The data would suggest that reducing the max force down to about 300 might negate the tendency of the wander force to push the agent into the wall, you might like to try that.

Visual Hints

As you have seen it is possible to render hints for each behaviour type e.g. whiskers for wall avoidance, detection box for obstacles. To show these hints use

renderer.showHints(flags);

where flags is the logical or-ing of the appropriate hint constants e.g.

renderer.showHints(Hints.HINT_WHISKERS | Hints.HINT_WANDER);

This table is a summary of the hints available - check out the documentation for the Picture and Hints classes for more detail.

Hint Constant Description
HINT_HEADING Shows the direction the agent is facing.
HINT_VELOCITY Shows the velocity vector. The length is proportional to the agent's speed.
HINT_COLLISION Shows the collision circle.
HINT_WHISKERS Shows the whiskers used to detect walls
HINT_OBS_AVOID Shows the detction box used in obstacle avoidance
HINT_WANDER Shows the wander circle and steering force used in the wander behaviour.
HINT_VIEW Shows the area of the world that can be viewed from this agent. Depends on view distance and the field of view for the agent.

Entity Mass

Changing the agent's mass does not affect on the balance between conflicting forces but I mention it here because increasing the mass will make the agent less responsive (more sluggish) to the applied forces. The default mass is 1.0 but it can be any value >0.0 but make it too big and the agent won't move - so be warned.

Summary

There is no exact solution to getting the agents movement just so - you have to experiment tweaking the auto-pilot!