Exemplo n.º 1
0
        public Vector3 GetSteering(ICollection <MovementAIRigidbody> targets)
        {
            Vector3 centerOfMass = Vector3.zero;
            int     count        = 0;

            /* Sums up everyone's position who is close enough and in front of the character */
            foreach (MovementAIRigidbody r in targets)
            {
                if (steeringBasics.IsFacing(r.Position, facingCosineVal))
                {
                    centerOfMass += r.Position;
                    count++;
                }
            }

            if (count == 0)
            {
                return(Vector3.zero);
            }
            else
            {
                centerOfMass = centerOfMass / count;

                return(steeringBasics.Arrive(centerOfMass));
            }
        }
Exemplo n.º 2
0
        public Vector3 GetSteering(ICollection <MovementAIRigidbody> targets)
        {
            Vector3 accel = Vector3.zero;
            int     count = 0;

            foreach (MovementAIRigidbody r in targets)
            {
                if (steeringBasics.IsFacing(r.Position, facingCosineVal))
                {
                    /* Calculate the acceleration we want to match this target */
                    Vector3 a = r.Velocity - rb.Velocity;

                    /* Rather than accelerate the character to the correct speed in 1 second,
                     * accelerate so we reach the desired speed in timeToTarget seconds
                     * (if we were to actually accelerate for the full timeToTarget seconds). */
                    a = a / timeToTarget;

                    accel += a;

                    count++;
                }
            }

            if (count > 0)
            {
                accel = accel / count;

                /* Make sure we are accelerating at max acceleration */
                if (accel.magnitude > maxAcceleration)
                {
                    accel = accel.normalized * maxAcceleration;
                }
            }

            return(accel);
        }