Exemple #1
0
        public void OnTriggerStay(Collider other)
        {
            if (!IsAnimalAi(other))
            {
                return;
            }

            if (IsSelf(other))
            {
                return;
            }

            var direction = other.transform.position - gameObject.transform.position;
            var angle     = Vector3.Angle(direction, transform.forward);

            if (angle < 0.5 * FieldOfViewAngle)
            {
                RaycastHit ray;
                if (Physics.Raycast(transform.position, direction, out ray))
                {
                    var otherAnimal    = other.GetComponentInParent <AiRig>();
                    var collidedAnimal = ray.collider.GetComponentInParent <AiRig>();
                    if (collidedAnimal == otherAnimal)
                    {
                        ReportDetection(other);
                        return;
                    }
                }
            }
            if (Detected.Contains(other))
            {
                ReportUndetection(other);
            }
        }
Exemple #2
0
        public void OnTriggerExit(Collider other)
        {
            if (!IsAnimalAi(other))
            {
                return;
            }

            if (IsSelf(other))
            {
                return;
            }

            if (Detected.Contains(other))
            {
                ReportUndetection(other);
            }
        }