protected override IEnumerator AttackTimer()
{
agent.isStopped = true;
animator.applyRootMotion = true;
animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, true);
yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[0].attackTimer);
animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, false);
animator.SetBool(enemySO.meleeEnemyAttacks[1].attackName, true);
yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[1].attackTimer);
animator.applyRootMotion = false;
agent.isStopped = false;
agent.ResetPath();
agent.Warp(transform.position);
yield return new WaitForSeconds(0.1f);
SwitchState(EnemyStates.Moving);
}
does anyone know how to fix root motion issues? when the animation stops the enemy snaps back to the navmesh agent position, basically "rolling back"
using UnityEngine;
using UnityEngine.AI;
public class ApplyRootMotion : MonoBehaviour
{
[SerializeField] Animator animator;
[SerializeField] NavMeshAgent agent;
void Start()
{
animator = GetComponent<Animator>();
}
void OnAnimatorMove()
{
if (!animator.applyRootMotion) return;
agent.transform.position += animator.deltaPosition;
agent.transform.rotation *= animator.deltaRotation;
agent.nextPosition = agent.transform.position;
}
}
ApplyMotion is in the same object as the Animator