private void FindVisibleTargets() { if (fsm._currentState.StateName() != "chase state" && fsm._currentState.StateName() != "retreat state") { Collider[] possibleTgts = Physics.OverlapSphere(transform.position + Vector3.up * 18.0f, viewRadius, targetMask, QueryTriggerInteraction.Ignore); for (int i = 0; i < possibleTgts.Length; i++) { Transform tgt = possibleTgts[i].transform; if (tgt.root != transform) { Vector3 dirToTgt = (transform.position - tgt.position).normalized; if (Vector3.Angle(transform.forward, dirToTgt) < viewAngle / 2) { float distToTgt = Vector3.Distance(transform.position, tgt.position); if (!Physics.Raycast((transform.position + (Vector3.up * 18.0f)), dirToTgt, distToTgt, obstacleMask, QueryTriggerInteraction.Ignore)) { //Debug.Log(gameObject.name + " sees " + tgt.name); Health validTgt = tgt.GetComponent <Health>(); if (validTgt != null && fsm.getValidTargets.Contains(validTgt) == false) { fsm.AddTgtToSuperList(validTgt); shootingScript._hasLostTgt = false; fsm.SetChaseStateViaFieldOfView(); } else if (validTgt != null) { shootingScript._hasLostTgt = false; fsm.SetChaseStateViaFieldOfView(); } } } } else { continue; } } } }