Auto-pilot & Steering Behaviours
Any entity created using the Vehicle class will automatically have an auto-pilot. The user can program the auto-pilot by switching on and tweaking various steering behaviours.
Behaviour | Description |
---|---|
Seek | Move towards a target position |
Flee | Move away from a target position |
Arrive | Like seek but slow down and stop when the target is reached |
Wander | Move aimlessly arround the game domain |
Pursuit | Pursue another agent |
Evade | Move away from another agent |
Obstacle avoidance | Avoid obstacles by changing direction |
Wall avoidance | Avoid hitting walls by changing direction |
Interpose | Move to a position midway between two agents |
Hide | Hide from an agent by moving behind an obstacle |
Path following | Move along a user specified path. |
Offset pursuit | Follow another agent by a user specified offset. Useful for moving agents in formation. |
The following are called group behaviours because they take into consideration some or all of the other vehicles in the game world.
Behaviour | Description |
---|---|
Cohesion | Generates a force to draw neighbouring agents closer |
Separation | Generates a force that keeps agents apart |
Alignment | Generates a force that keeps neighbouring agents moving in the same direction |
Flocking | A combination of cohesion, separation and alignment to give flocking behaviour. |
All the steering behaviours are implemented in the AutoPilot class and you should look at the class class reference to find all the methods available.
Updating the Vehicle Physics
The physics engine is based around Newton’s laws of motion which state
- An object remains at rest or at a constant velocity (uniform motion) unless acted upon by a force.
- The acceleration of a body is directly proportional to, and in the same direction as, the net force acting on the body, and inversely proportional to its mass. Thus, F = ma, where F is the net force acting on the object, m is the mass of the object and a is the acceleration of the object.
It means that a Vehicle’s state (whether at rest or uniform motion) is only changed when a force is applied to it. When a behaviour is activate it applies a force to the Vehicle, the direction and magnitude of which depends on the behaviour type.
The physics update will calculate the force for each active behaviour, resolving them into a net force which is applied to the Vehicle to give it a new velocity vector.