Steering Behavior: Fleeing

Posted by: rocketman on June 12, 2010

Time for the next steering behavior, fleeing. This will use the same class and will be built off what we did in the seeking behavior. It is based on Craig Reynolds' article, Steering Behaviors For Autonomous Characters.

Fleeing is very similar to seeking. It is actually the inverse of seeking. Instead of going towards the target, fleeing goes away from the target. It works like this:

1. desiredVelocity = target - position

2. desiredVelocity is normalized and multiplied by maxSpeed.

3. desiredVelocity is multiplied by -1 to go away from the target

4. steeringForce = desiredVelocity - velocity

5. update the vehicle.

In code, it looks like this:

var desiredVelocity:Vector2D = target.subtract(position).normalize().multiply(maxSpeed);
var steeringForce:Vector2D = desiredVelocity.subtract(velocity);

Click here to see fleeing in action!

After we finish these basic behaviors, the fun behaviors get to come out!

Steering Behavior2DMathVector

Current rating: 5


  • There are currently no comments

New Comment

required (not published)
  • Back in July, we looked at how to use Ray Casting for collision detection. We also learned how to use the Separation of Axis Theorem. I recently had a request for a way to use the Shapes we created here with the Ray Casting method.¬†First, lets do a quick review of the shape classes. read more
    5 years, 5 months ago
  • Today we will finally be detecting a collision with SAT. We know how SAT works, we've built classes to work with SAT, now we can use all of this to detect a real, live collision! read more
    5 years, 8 months ago
  • A few months ago, I posted on the separation of axis theorem. You can learn all about SAT and how it works here. What that post failed to do was use the SAT. We will explore using SAT for collision detection in this post. read more
    5 years, 8 months ago
  • Some of you have asked for the entire steering behavior source as well as the A* source. Here is the zip with all the classes. In there is the vehicle... read more
    5 years, 8 months ago
  • In the last three posts, we explored the how A* works, then we put A-star into code, then we looked at different heuristics for A*. Now we will combine A*... read more
    5 years, 8 months ago
RSS / Atom