예제 #1
0
        /// <summary>
        /// The Cohesion behavior. Returns the required acceleration for the cohesion behaviour
        /// </summary>
        public Vector3 GetSteering(ICollection <Rigidbody> agents)
        {
            if (agents == null || agents.Count == 0)
            {
                return(Vector3.zero);
            }

            var centerOfMass = Vector3.zero;
            var count        = 0;



            /* Sums up everyone's position who is close enough and in front of the character */
            foreach (var r in agents)
            {
                if (_steeringBasics.IsFacing(r.position, _facingCosineVal) == false)
                {
                    continue;
                }

                centerOfMass += r.position;
                count++;
            }

            return(count == 0 ? Vector3.zero : _arrive.GetSteering(centerOfMass / count));
        }