public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _linear   = FixVec2.Zero;
            _position = owner.Get <Position>().Value;

            Proximity.FindNeighbors(owner, _proximityCallback);

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

            if (_linear.MagnitudeSqr == 0)
            {
                return(SteeringVelocity.Zero);
            }

            _linear.Normalize();
            _linear.Scale(ref maxVelocity);

            return(new SteeringVelocity(_linear));
        }
Beispiel #2
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _averageVelocity = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                var maxVelocity = owner.Get <MaxVelocity>().Value;

                _averageVelocity /= neighborCount;

                if (_averageVelocity.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _averageVelocity.Normalize();
                _averageVelocity.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_averageVelocity));
        }
Beispiel #3
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _centroid = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                _centroid /= neighborCount;
                _centroid -= owner.Get <Position>().Value;

                if (_centroid.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _centroid.Normalize();

                var maxVelocity = owner.Get <MaxVelocity>().Value;
                _centroid.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_centroid));
        }