private void GetClosestThreat() { float closest = -1; var previousTarget = m_target; bool isNewTargetFound = false; for (int i = 0; i < m_threatList.Count; i++) { float currentDist = StaticUtil.FastDistance(this.transform.position, m_threatList[i].transform.position); if (currentDist > closest) { closest = currentDist; if (m_target != m_threatList[i] && !m_threatList[i].isDead) { m_target = m_threatList[i]; if (m_target != previousTarget) { m_attackRangeModifier = m_target.GetComponent <AgentAttackRangeModifier>(); } isNewTargetFound = true; } } } if (m_target.isDead && !isNewTargetFound) { m_target = m_treeOfLife; } }
private void ScanForThreats() { for (int i = 0; i < vThirdPersonControllerRepository.Players.Count; i++) { if (StaticUtil.FastDistance(this.transform.position, vThirdPersonControllerRepository.Players[i].transform.position) < SightRange) { if (m_threatList.Contains(vThirdPersonControllerRepository.Players[i]) == false && !vThirdPersonControllerRepository.Players[i].isDead) { m_threatList.Add(vThirdPersonControllerRepository.Players[i]); } } } m_lastScan = Time.time; }
private void Attack() { var distance = StaticUtil.FastDistance(m_target.transform.position, this.transform.position); if (!m_target.isDead && ((m_attackRangeModifier && distance <= m_attackRangeModifier.AgentAttackRange) || distance < AttackRange)) { m_animator.SetTrigger("IsAttacking"); m_animator.SetFloat("MoveSpeed", 0); RotateTowardsTarget(); m_mood = Mood.Attack; } else { m_mood = Mood.Chase; } }
private void Chase() { GetClosestThreat(); if (m_target) { m_agent.SetDestination(m_target.transform.position); m_animator.SetBool("IsMoving", true); var distance = StaticUtil.FastDistance(m_target.transform.position, this.transform.position); if ((m_attackRangeModifier && distance <= m_attackRangeModifier.AgentAttackRange) || distance < AttackRange) { m_mood = Mood.Attack; RotateTowardsTarget(); Attack(); } } if (m_target.isDead) { m_mood = Mood.Wander; } }