public override Status Tick() { // Set the guard to stand with the agent they are conversing with if (guardblackboard.finishedConversation == false) { navAgent.isStopped = true; guardblackboard.SetState(Guardblackboard.GuardState.converse); } // Look at the agent if (guardblackboard.GetGuardState() == Guardblackboard.GuardState.converse) { guardblackboard.gameObject.transform.LookAt(guardblackboard.nearbyFriendly.transform); } // Once the conversation has finished then reset values and continue on patrol route if (guardblackboard.finishedConversation) { Debug.Log("Finished conversation"); navAgent.isStopped = false; navAgent.SetDestination(guardblackboard.destination); guardblackboard.nearbyFriendly = null; guardblackboard.SetState(Guardblackboard.GuardState.idle); guardblackboard.nearbyFriendly = null; guardblackboard.SetTriedToConverse(true); guardblackboard.finishedConversation = false; // Reset conversation time if (guardblackboard.conversationTimer <= 0) { guardblackboard.conversationTimer = time; } return(Status.SUCCESS); } return(Status.RUNNING); }
private void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Player") { playerInSight = false; // If the player enters the guards detection zone, direction towards the player and convert to an angle Vector3 vectorToPlayer = other.transform.position - transform.position; float angle = Vector3.Angle(vectorToPlayer, transform.forward); // If the angle is less that half the guards view angle player is within the guards LoS if (angle < fieldOFViewAngle * 0.5f) { RaycastHit hit; // Exclude enemy layer int layerMask = 1 << 10; layerMask = ~layerMask; // Create a raycast to ensure that the player is visible and not hidden behind an object or in other room if (Physics.Raycast(transform.position + Vector3.up, vectorToPlayer.normalized, out hit, detectionZone.radius, layerMask)) { Debug.DrawRay(transform.position + Vector3.up, vectorToPlayer, Color.green); // Draw a line towards the player // If the player has been seen, update relevant systems if (hit.collider.CompareTag("Player")) { playerInSight = true; guardBlackboard.playerInSight = true; globalBlackboard.playerLastSighting = player.transform.position; guardBlackboard.playerPosition = player.transform.position; guardBlackboard.SetState(Guardblackboard.GuardState.combat); } } } } }