Time for the next steering behavior, fleeing. This will use the same Vehicle.as 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.
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); velocity.add(steeringForce.divide(mass).multiply(-1));
After we finish these basic behaviors, the fun behaviors get to come out!Steering Behavior2DMathVector Share on Twitter Share on Facebook