public NPC_Alert(NPC_BehaviorAI npcStatePattern) { npc = npcStatePattern; npcSight = npc.npcSight; npcMove = npc.npcMove; npcStats = npc.npcStats; }
void Start() { if (npc == null) { npc = GetComponent <NPC_BehaviorAI>(); } offset = npc.head.position.y; }
// Calculates if npc can see target. public bool CanSeeTarget(NPC_BehaviorAI npc, Transform target) { VisibilityCalculations(target); if (Vector3.Distance(headPosition, targetPosition) < npc.sightRange && angleBetweenNpcAndPlayer < npc.viewAngle / 2f && Physics.Linecast(npc.transform.position, target.position, npc.myObstacleLayer) == false) { npc.hasTargetInSight = true; return(true); } npc.hasTargetInSight = false; return(false); }
void InformNearbyAllies() { // string alliesInformed = ""; if (Time.time > nextInform) { nextInform = Time.time + informRate; friendlyColliders = Physics.OverlapSphere(npc.transform.position, npc.sightRange, npc.myFriendlyLayers); if (friendlyColliders.Length == 0) { return; } foreach (Collider ally in friendlyColliders) { if (ally.transform.root.GetComponent <NPC_BehaviorAI>() != null) { NPC_BehaviorAI allyPattern = ally.transform.root.GetComponent <NPC_BehaviorAI>(); if (allyPattern.currentState == allyPattern.patrolState) { allyPattern.pursueTarget = npc.pursueTarget; allyPattern.hasLocationOfInterest = true; allyPattern.locationOfInterest = npc.pursueTarget.position; allyPattern.currentState = allyPattern.alertState; // allyPattern.npcMaster.CallEventNpcWalkAnim(); // alliesInformed += ally.gameObject.name + "\n"; Debug.Log(npc.gameObject.name + " is informing " + ally.gameObject.name); } } } } // Debug.Log(alliesInformed); }
float minRange = 5; // The range for when the npc should move to target location. If target is within range, npc will not move. public NPC_Movement(NPC_BehaviorAI _npc) { npc = _npc; npcStats = npc.npcStats; npcSight = npc.npcSight; }
public NPC_Sight(NPC_BehaviorAI _npc) { npc = _npc; npcStats = npc.npcStats; }
void Awake() { npc = GetComponent <NPC_BehaviorAI>(); }