Beispiel #1
0
        protected override Vector2 OnUpdateSteeringForce(float elapsedTime, Steerable movingEntity)
        {
            if (MovesPerMinute < 0f)
            {
                MovesPerMinute = 0f;
            }

            // Check if we are outside our moving range
            if (Vector2.Subtract(movingEntity.Position, location).LengthSquared() > PatrolRange * PatrolRange * 1.2F)
            {
                timer    = (float)(Random.NextDouble() * 60 / (MovesPerMinute + 0.001f));
                location = movingEntity.Position;
            }

            // Select a random location when the timer expires
            timer -= (float)elapsedTime;

            if (timer < 0)
            {
                Vector2 target = new Vector2();

                float a = (float)(Random.NextDouble() * Math.PI * 2);
                float r = (float)(Random.NextDouble());

                target.X = (float)(Math.Cos(a) * PatrolRange * r);
                target.Y = (float)(Math.Sin(a) * PatrolRange * r);

                movingEntity.Target = target + location;

                timer = (float)(Random.NextDouble() * 60 / (MovesPerMinute + 0.001f));
            }

            return(SteeringHelper.Arrive(elapsedTime, movingEntity));
        }
Beispiel #2
0
 protected override Vector2 OnUpdateSteeringForce(float elapsedTime, Steerable movingEntity)
 {
     return(SteeringHelper.Arrive(elapsedTime, movingEntity));
 }