/// <summary> /// This behavior is similar to seek but it attempts to arrive at the /// target with a zero velocity /// </summary> /// <param name="target"></param> /// <param name="decel"></param> /// <returns></returns> protected Vector2D calculateArriveVector(Vector2D target, DecelerationState decel) { Vector2D toTarget = target - _player.Position; //calculate the distance to the target double dist = toTarget.Length; if (dist > 0.0) { //because Deceleration is enumerated as an int, this value is required //to provide fine tweaking of the deceleration.. double decelerationTweaker = 0.3; //calculate the speed required to reach the target given the desired //deceleration double speed = dist / ((double)decel * decelerationTweaker); //make sure the velocity does not exceed the max speed = Math.Min(speed, _player.MaxSpeed); //from here proceed just like Seek except we don't need to normalize //the ToTarget vector because we have already gone to the trouble //of calculating its length: dist. Vector2D desiredVelocity = toTarget * speed / dist; return(desiredVelocity - _player.Velocity); } return(new Vector2D(0, 0)); }
/// <summary> /// This behavior is similar to seek but it attempts to arrive at the /// target with a zero velocity /// </summary> /// <param name="target"></param> /// <param name="decel"></param> /// <returns></returns> protected Vector2D calculateArriveVector(Vector2D target, DecelerationState decel) { Vector2D toTarget = target - _player.Position; //calculate the distance to the target double dist = toTarget.Length; if (dist > 0.0) { //because Deceleration is enumerated as an int, this value is required //to provide fine tweaking of the deceleration.. double decelerationTweaker = 0.3; //calculate the speed required to reach the target given the desired //deceleration double speed = dist / ((double)decel * decelerationTweaker); //make sure the velocity does not exceed the max speed = Math.Min(speed, _player.MaxSpeed); //from here proceed just like Seek except we don't need to normalize //the ToTarget vector because we have already gone to the trouble //of calculating its length: dist. Vector2D desiredVelocity = toTarget * speed / dist; return (desiredVelocity - _player.Velocity); } return new Vector2D(0, 0); }