Exemplo n.º 1
0
        private static SteeringVelocity Arrive(Entity <Game> owner, FixVec2 target)
        {
            var tolerance = owner.Get <ArrivalTolerance>();
            var position  = owner.Get <Position>().Value;

            target.Sub(ref position);

            var distance = target.Magnitude;

            if (distance <= tolerance.Distance)
            {
                return(SteeringVelocity.Zero);
            }

            var maxVelocity          = owner.Get <MaxVelocity>().Value;
            var decelerationDistance = tolerance.DecelerationDistance;

            if (distance <= decelerationDistance)
            {
                maxVelocity *= distance / decelerationDistance;
            }

            var velocity = target / distance * maxVelocity;

            return(new SteeringVelocity(FixVec2.ClampMagnitude(velocity, maxVelocity)));
        }