public void Death() { animator.SetTrigger("death"); animator.SetInteger(EnemyAIManager.Instance().transitionParameter, (int)Transition.DEATH); enabled = false; solidPhysicalCollider.enabled = false; }
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (ChaseState.ShouldChasePlayer(animator.transform.position)) { animator.SetInteger(EnemyAIManager.Instance().transitionParameter, (int)Transition.CHASE); } else if (!navAgent.hasPath) { animator.SetInteger(EnemyAIManager.Instance().transitionParameter, (int)Transition.IDLE); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) //{ // //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) //{ // //} // OnStateMove is called right after Animator.OnAnimatorMove() override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!ShouldChasePlayer(animator.transform.position)) { animator.SetInteger(EnemyAIManager.Instance().transitionParameter, (int)Transition.IDLE); } else { if (!navAgent.hasPath || (player.transform.position - navAgent.pathEndPosition).sqrMagnitude > repathTolerance * repathTolerance) { SetDestinationNearTarget(navAgent, player); } } }
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 static bool ShouldChasePlayer(Vector3 chaserPosition) { ThirdPersonControl p = EnemyAIManager.Instance().player; return((p.transform.position - chaserPosition).sqrMagnitude < chaseRadius * chaseRadius); }