//Entering Detection Sphere - switch to Physics.overlapshpere? void OnTriggerStay(Collider other) { // Timer for additional optisation? if (other.gameObject.tag == typeOfTarget.ToString() && ai.currentState != NpcAi.State.Init) { if (ai.currentState == NpcAi.State.Idle || ai.currentState == NpcAi.State.Patrol || ai.currentState == NpcAi.State.Chase || ai.currentState == NpcAi.State.Investigate || ai.currentState == NpcAi.State.Attack) { targetInSight = false; Vector3 direction = other.transform.position - transform.position; float angle = Vector3.Angle(direction, transform.forward); //Sight if (angle < fieldOfView * 0.5f) { RaycastHit hit; if (Physics.Raycast(transform.position + transform.up, direction.normalized, out hit, col.radius, detectionMask)) { if (hit.collider.gameObject.tag == typeOfTarget.ToString()) { targetInSight = true; Debug.DrawLine(transform.position, hit.transform.position, Color.red, 0.1f, true); if (ai.myTarget == null) { senseTarget = hit.transform.gameObject; ai.SetTarget(senseTarget); //Debug.Log ("Target Aquired!"); } } else { if (senseTarget != null && targetInSight == false) { //Line of sight has been broken! //ClearTarget(); //ai.GoInvestigate(other.transform.position); } } } } //Hearing // if(ai.currentState != NpcAi.State.Chase && ai.currentState != NpcAi.State.Attack)//they are effectivly deaf when engaging an enemy // { // if(CalculatePathLength(other.transform.position) <= col.radius /2) //back here later // { // //ai.GoInvestigate(other.transform.position); // //Debug.Log ("Heard the Player!!"); //Carefull here, requires externa critera for solid logic gate // } // } } //State Logic gate end } }