Synchronizing Root Motion with Nav Mesh Agent

Hello,

I made that spiderish turret model as an enemy in my game, and writed an AI for it. AI was working pretty well until I implement root motion animations. I did all that rigging stuff and walking animations etc. but when I tried to implement it, everytime my model was not at the same position with its nav mesh agent’s position so because of it it looks like its sliding while walking. I tried so much things but nothing fixed it and Im working on it like for 1.5 or maybe 2 months.

I added only the patroling function of it cuz all code is 863 lines and the patroling part is the shortest function of AI (Also basicly I used SetDestination() functiıon in other functions at the end so… They are all are same at some point). If you need more info about code or something else please share it.

private void Start()
{
        //Enenmy AI
        agent = GetComponent<NavMeshAgent>();
}
private void OnAnimatorMove()
{
        Vector3 rootPos = animator.rootPosition;
        rootPos.y = agent.nextPosition.y;
        transform.position = rootPos;
        agent.nextPosition = rootPos;

        //agent.transform.position += animator.deltaPosition;
}

private void Update()
{
        //I moved them here from Awake() cuz some errors, in the Update() there is no errors.
        agent.updatePosition = false;
        agent.updateRotation = true;

        distanceBetween = Vector3.Distance(transform.position, player.transform.position); //For Selecting Gear & Adjusting Distance

        if (canPatrol == true)
             turretPatroling();
}

public void turretPatroling()
{
        if (agent.remainingDistance <= agent.stoppingDistance)
        {
            Vector3 point;
            if (RandomPoint(centerPoint.position, range, out point)) //In the RandomPoint() there is no code for animation, only some calculations about randomly selecting a destination (vector3)
            {
                var rotationY = transform.rotation.y;

                agent.SetDestination(point);
            }
        }
}

Thats the turret :

Ekran görüntüsü 2024-01-17 192945

The AI code I talked about is attached to TurretBody, parent object is just an empty object at the same position as TurretBody and Head script basicly controls all the head motions or some shooting things etc.

Ekran görüntüsü 2024-01-17 194435

There is an example of the problem: