private void Update() { // Prevent enemy activity during death animation if (_stats.isDead) { return; } // Ensure current target is up to date _currentTarget = _brain.GetCurrentTarget(); // Follow current aggro decision if (_currentTarget && _agent.enabled) { _agent.SetDestination(_currentTarget.position); float distance = (_currentTarget.position - transform.position).sqrMagnitude; if (distance <= _agent.stoppingDistance * _agent.stoppingDistance) { FaceTarget(); } } // Trigger walking animation _anim.SetFloat("WalkSpeed", _agent.velocity.magnitude); }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null) { // No target player, return to idle animator.SetBool("IsAggro", false); return; } // Always face player if they are not in the field of attack if (Vector3.Angle(_target.position - animator.transform.position, animator.transform.forward) > 10f && !_motor.IsRotating) { _motor.StartRotate(); } else if (_motor.IsRotating) { _motor.StopRotate(); } // Try to attack player if (!_combat.IsCoolingDown) { _combat.ChooseAttack(); } }
private IEnumerator FollowTarget() { while (IsFollowing) { if (!_ignoreBrain) { _target = _brain.GetCurrentTarget(); } if (_target && _agent.enabled && !_stats.isDead) { _agent.SetDestination(_target.position); } // Delay loop to increase lessen load on path finding yield return(new WaitForSeconds(0.1f)); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } if (_brain.GetCurrentTarget()) { animator.SetBool("IsAggro", true); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null) { return; } // See if we can use our special attack if (_combat.CanUseSpecialAttack) { _combat.SpecialAttack(); return; } float distance = Vector3.Distance(animator.transform.position, _target.position); if (distance <= _brain.attackRadius) { // See if we need to rotate towards the player float angle = Vector3.SignedAngle(_target.position - animator.transform.position, animator.transform.forward, Vector3.up); if (Mathf.Abs(angle) > angleFromTargetTolerance && distance <= _combat.meleeDistance) { animator.SetTrigger(angle < 0 ? "RotateLeft" : "RotateRight"); return; } if (!_combat.IsCoolingDown) { // Go to attack state bool choseAttack = _combat.ChooseAttack(); if (choseAttack) { return; } } } // Follow player if necessary if (distance > _agent.stoppingDistance) { animator.SetTrigger("Follow"); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null) { return; } // See if we can use our special attack if (_combat.CanUseSpecialAttack) { _combat.SpecialAttack(); return; } float distance = Vector3.Distance(animator.transform.position, _target.position); // Try to attack player if they are close enough if (distance <= _brain.attackRadius) { if (Vector3.Angle(_target.position - animator.transform.position, animator.transform.forward) > angleFromTargetTolerance) { animator.SetTrigger("Rotate"); return; } if (!_combat.IsCoolingDown) { // Go to attack state _combat.ChooseAttack(); return; } } // Move to target player if necessary if (distance > _agent.stoppingDistance) { animator.SetTrigger("Follow"); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null) { return; } float distance = Vector3.Distance(animator.transform.position, _target.position); // Try to attack player if they are close enough if (distance <= _brain.attackRadius) { if (canRotate && Vector3.Angle(_target.position - animator.transform.position, animator.transform.forward) > angleFromTargetTolerance) { animator.SetTrigger("Rotate"); return; } if (!_combat.IsCoolingDown) { // Go to attack state bool choseAttack = _combat.ChooseAttack(); if (choseAttack) { return; } } } // Follow player if possible and necessary if (canFollow && distance > _agent.stoppingDistance) { animator.SetTrigger("Follow"); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null && !_agent.hasPath) { animator.SetTrigger("Idle"); return; } if (_agent.enabled && _target) { // See if we can use our special attack if (_combat.CanUseSpecialAttack) { _combat.SpecialAttack(); return; } if (!_combat.IsCoolingDown && Vector3.Distance(_target.position, animator.transform.position) <= _brain.attackRadius) { // Go to attack state bool choseAttack = _combat.ChooseAttack(); if (choseAttack) { return; } } } animator.SetFloat("WalkSpeed", _agent.velocity.magnitude); }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target) { _angle = Vector3.SignedAngle(_target.position - animator.transform.position, animator.transform.forward, Vector3.up); } // If there is no target within reach, or within 30 degree view of target, exit state if (_target is null || Vector3.Distance(_target.position, animator.transform.position) > _brain.attackRadius || Mathf.Abs(_angle) < tolerance) { animator.SetTrigger("Idle"); } animator.SetFloat("RotationSpeed", _angle < 0f ? -1f : 1f); }