Steering Behaviors: Arrival
- Steering Behaviors: Wander
- Steering Behaviors: Pursuit and Evade
- Steering Behavior: Fleeing
- Steering Behaviors: Seeking
- Steering Behaviors: Arrival
- Steering Behaviors: Obstacle Avoidance
- Steering Behaviors: Unaligned Collision Avoidance
- Steering Behaviors: Flow Field Following
- Steering Behaviors: Path Following
- Steering Behaviors: Flocking
Next in the series on Steering Behaviors is arrival. As always, we will be using the Vehicle.as class. It is based on Craig Reynolds’ article, Steering Behaviors For Autonomous Characters.
The arrival behavior is almost exactly like seeking, except it has a little, but useful, twist. When the vehicle is seeking a target and it reaches the target, its velocity is greater than 0 and it continues to move, thus overshooting the target. So the vehicle turns around and does it again. This results in an oscillation around the target point.
Arrival fixes this behavior. As the vehicle approaches the target, it slows down coming to a nice stop on the target, just like a car stopping at a red light.
It works like this:
1. Find the desired velocity (the straight line between the position and the target) and normalize it
2. Find the distance between the position and the target
3. If the distance is not within the slowing distance, go at full speed
4. If you are within the slowing distance, start slowing down to get a nice stop
5. Keep the force within the max force, and apply it.
In as3:
private var slowingDistance:Number = 20;//slowing distance, you can adjust this
public function arrive(target:Vector2D):void {
var desiredVelocity:Vector2D = target.cloneVector().subtract(position).normalize();//find the straight path and normalize it
var distance:Number = position.distance(target);//find the distance
if(distance > slowingDistance){//if its still too far away
desiredVelocity.multiply(_maxSpeed);//go at full speed
} else {
desiredVelocity.multiply(_maxSpeed * distance/slowingDistance);//if not, slow down
}
var force:Vector2D = desiredVelocity.subtract(velocity).truncate(_maxForce);//keep the force within the max
velocity.add(force);//apply the force
}
| Print article | This entry was posted by rocketman on June 18, 2010 at 11:00 AM, and is filed under AI, AS3, Steering. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |









about 1 year ago
I’d like to know how to stop the vehicle without changing its rotation.