override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (navAgent == null) { navAgent = animator.GetComponentInParent <NavMeshAgent>(); } if (player == null) { player = EnemyAIManager.Instance().player; } // Reset the path so the AI could create new path to chase the player navAgent.ResetPath(); navAgent.speed = runSpeed; }
public void SetDestinationNearTarget(NavMeshAgent agent, ThirdPersonControl target) { NavMeshHit hit; float radius = 0; for (int i = 0; i < repeatCount; i++) { Vector3 randomPosition = Random.insideUnitSphere * radius; randomPosition += target.transform.position; if (NavMesh.SamplePosition(randomPosition, out hit, radius, 1)) { agent.SetDestination(hit.position); break; } else { ++radius; } } }
public static bool ShouldChasePlayer(Vector3 chaserPosition) { ThirdPersonControl p = EnemyAIManager.Instance().player; return((p.transform.position - chaserPosition).sqrMagnitude < chaseRadius * chaseRadius); }