Agent follows character(Animation)

I have been trying to develop a Legends of Zelda game for a while. One of the core functionality is to have NPC and the boss in the boss level roam their Arenas before spotting Link. I was very unhappy with the way the NPCs looked when the animation followed the animation (caused the gliding effect of the feet, which is well documented and the fix is readily available on the unity manual in this link here.(I am using the “if you want the agent to follow the character” part.)) The problem now is that I have not been able to find a single forum post or a YouTube video discussing this, is that the nav mesh agent settings are all now useless. In fact, not only are they useless, but changing anything from character speed, acceleration, and angular speed from the nav mesh agent all break the patrolling behavior of the agent. It is noteworthy that I have copied and pasted all the code for both patrolling and the animation coupling from the manual, but it still completely breaks and I cannot find a way to make my character walk during patrolling instead of running.

I am using the patrolling script found here.
For animations, I am using a blend tree-like referred to in the unity tutorial that blends walking, running, and turning.It is working fine and is working just as expected. So far, due to the high velocity of the agent trying to reach the waypoints, the NPCs are always running. Trying to divide the velocity calculated by an arbitrary float also leads to breaking the patrolling behavior somehow. I have tried to brute force by dividing everything and anything but any constants (such as dividing velx and vely by any constant) but the result is always the same. It leads to either the animation jittering and not being acceptable at all, or leads to the agent completely going off course during patrolling. If anyone knows any way to modulate the speed of patrolling without breaking anything or if there is a standard way of modulating agent speed after applying this animation coupling where the agent follows the character animation, I am all ears and greatly appreciate your help. Thank you all for your time in advance.

Hi Michael,

If we ignore the animation for now, the speed parameter in the NavMeshAgent component (visible in the inspector) on your patrolling gameobject (enemy) is what is setting the speed of the agent. Are you happy that you can set the value for that speed from your code and you can see the results? i.e, if you set it to a value of 0.1 the objects patrols really slowly or if you set it to a value of 10 it patrols significantly faster.

If the above is not behaving as you expect then we need to fix this first before worrying about the animation. You could also set the speed value in the Inspector to limit how fast the agent can move.

Assuming the above works, you would need to set your NavMeshAgent speed to the value in the blend tree where the walking animation occurs.

If we look at the example screenshot you have in your link above…


…we can see that if you were sending a value of 3.87 or higher to the vely parameter, your run animation would be playing at full speed.
If you also had a walk animation in here, your blend tree should show the value that it needs vely to be in order to play the walk at full speed before it blends into the run animation. It is that value you want to be sending to your NavMeshAgent speed parameter. (Again, you could set this value directly in the inspector for initial testing)

Hope this makes some sense.