What's the point? This hero movement (is sliding) because its not based on root motion (animation not sync with move). Root motion: nav.nextPosition = transform.position;
The complexity here is that both the animation system and the navigation system are trying to change the position of the agent, as explained in the video. In OnAnimatorMove() I actually have the reverse of your suggestion to keep the NavMeshAgent and the animated agent at the same position. What I show in the video worked best after a bunch of experiments that I tried, but there may be other good solutions to this problem as well.
Wow, amazing! I was looking for an example of navmesh + animation without jittering, and found it here. Animations are smooth, especially when added more animations to blend tree. please keep doing awesome content like this
Oh man, I spent WEEKS trying to do this, UNTIL I came across your videos! You've saved me TONS of hours of experiments! Thank you so VERY much for your channel! Subscribed & like! Thanks again Sir!!!
When I first got into unity I really thought it was gonna be like Legos. Ah, poor naive slightly (6 months) younger me. Been digging for a while to find videos describing the process of merging various pieces of things, and I think this may be the only one on youtube, so thank you for making this. Even if it's not for these exact assets, it gives me an idea of what's needed, and I can play around from there. That said, if anyone who sees this comment wants to chime in with other great sources of info on the subject, I'd appreciate it greatly. Lol. So many great packages, and so many things, but man, it sure seems like combining parts for a different car. Sure, a Honda fuel pump will work in a Ford, but it takes a loooot of hacking at it.
Found this video today after struggling with animations for weeks. I'm so glad I found this because now, I'm going to hopefully be able to finish my game.
@@ClockworksGames One question. I can't seem to get a hold of the Standard Assets animations. Would you say that I can substitute the animations with animations from Mixamo?
@@ClockworksGames I found them in the link you provided. Some of the links have changed, which is why I was confused but, I found the assets eventually.
Great video! Is it possible for you somehow to share o show all the animation clips. I´d love to see how turn left and right animations were made to work with navmesh. Thanks for the video!
Thanks for the nice comment! All the animation clips are from the Unity Standard Assets which used to be available for free on the Asset Store, but unfortunately are no longer available.
This is very helpful, I am a little confused as to the transform.position = agent.nextPosition bit (I understand what it stops the agent doing) but doesn't it just negate the rootmotion? the character will move as if the it just had the basic nav agent movement?
Thanks for the question. The main movement of the agent is driven by the animation clips in the Update() function. The line that you mentioned, called in OnAnimatorMove() just provides a small correction because the NavMesh agent and the character model would gradually drift apart otherwise.
@@ClockworksGames I believe Cunnah is correct here. agent.updatePosition = false; only stops the transform from being updated by the agent automatically, but the nextPosition will keep simulating to its destination. You correctly use the agent properties to derive animation parameters and let RootMotion take control of the player transform. You also correctly state that this would result in the agent's nextPosition deviating from the animation's derived transform position. When you implement OnAnimatorMove the animation will no longer update the transform directly, so the idea here is to use your animation's positionDelta as input for moving the transform manually with contraints. Your constraint here is just to set the transform back to the agent's nextPosition, bypassing root motion all-together. What you actually want to do is use the animation's positionDelta and override the agent's nextPosition = calculatedPosition (which will apply navmesh boundaries), then you can set the transform position to the agent's nextPosition. The result is you used the initial agent's velocity to set root motion parameters, and root motion velocity to then update the agent's position, then setting the transform to the new agent position to sync them.
@@robu4005 Thanks for this comment. I have been trying to understand what you said in detail. Do you think something in my approach is not correct or, if correct, could have been done better? I am not surprised if there is yet a better approach. As I mentioned in my video, I tried a lot of things, and what I showed is what seemed to have the best results. But there may certainly be opportunities to improve on it. I would like to understand the details of what you are saying. Thanks again!
I used a couple of animations from Mixamo. Weirdly when I automatically calculated the blend values it produced the wrong values. The animation actually moves the character much faster then the animator blend values suggest. I manually figured out the velocities and used those and it works correctly. Whats up with that?
@@ClockworksGames Sure thing, as I cannot link you the exact animation it is called "Rifle Run" and it is the version where the character is not pointing the rile ahead. They are holding it down and it is moving back and forth. It is the 3rd option when I search for "Rifle Run". Let me know if you want to make sure you have the right one.
@@ChadGatling Ok, I think I've found and downloaded the correct Rifle Run animation. What other animation clips are you blending this with? Are you using Mixamo animations for idle / walk / turn ? (You can also email me at info@clockworks-games.com if you prefer to communicate through direct email.)
I didn't need all the controls to move a char in real time because I'm making a tower defense and have enemy AI characters heading toward a goal point. I found a much easier way to do what I needed. I just wanted the animation to move the enemy toward a set goal point so that it would move at the speed of the animation itself rather than being "pushed" along by the navmeshagent comoponent. To accomplish this, I set agent.updatePosition = false and turned root motion on for the walk animation clip. All I needed was an if condition to check when the enemy position was at the goal point, in which case I set the animation controller enabled to false to make the enemy stop. It's that simple.
@@ClockworksGames In this approach, the forward pace is driven by the root motion of the walk/run clip, so there is no foot sliding. I did get my simplified approach to work under test circumstances, but it turns out that it's not the right way because the navmesh still controls the rotational steering while the forward motion is driven by the root motion of the animation. What can happen is the character will seem to get lost if the navmesh component is not keeping perfect pace with the character. For now I'm using a multiplier for the navmesh speed so that it can provide correct timing of the rotational steering. I'll probably implement the "recommended" approach later in my project.
@@StygianStyle Thanks for describing your approach. There are many ways to do all these things, and it often takes experimentation to find out what will work.
Amazing tutorial. I was just wondering if you're gonna make any future tutorials on Enemy State machine behaviors such as chasing, attacking with the root motion system.
Thanks very much for the nice feedback! I have a roadmap of upcoming videos including NPC / enemy behaviors, senses of different kinds, and associating reactions with senses. I will add some discussion of state machines as well, which will certainly be required.
@@michaelgeorge4524 I see that Unity has recently removed their Standard Assets from the Asset Store, unfortunately. I will look for a replacement. Unity has a new "Starter Asset - Third Person Character Controller" which has idle, walk, and run animation clips, but no turning. That could be used, but I will look to see whether there are any free clips available that include turning.
@@brionsarachan4500 yea without a proper set of animations, it doesn't work properly at all. Keep me updated if you have found anything that works please tell me
I was able to get my hands on animations that make it work and just mirrored all the animations to generate turning effects. The bigger problem I have now is that I cannot modulate the speed on the NPC at all. The NPC is constantly running, after applying the code which I know is part of Unity's make the agent follow the animation tutorial, changing agent speed does not do anything anymore. I want to force the patrolling of an area to be slower but it seems to not be possible after making the speed of the agent be animation based somehow
Are you using animations with root motion for the move state or are they only moving in place? That is the thing I cannot figure out, wether I should move by animation or by agent.
The animations do use root motion. The position of the NavMeshAgent is decoupled from the animated character using agent.updatePosition = false. The agent's calculated next position is used to adjust the parameters of the animator controller to drive the animation which moves the character. There is a small tweak in OnAnimatorMove() that prevents the character and the NavMeshAgent from drifting apart. Let me know if this isn't clear.
@@ClockworksGames Thanks! It took me a lot to wrap my head around using root motion when every teacher all my life has advised me against it, but the system works, and the solution is simple, elegant and beautiful. So I have no complains here. I have one question though. You set up animations to rotate on place in the animator, but these never seem to get triggered in your project or mine. I'm guessing the 'velx' animator parameter should be modified while keeping move=false to achieve this. How would you go about implementing these? Maybe check in update if the angle between desiredDirection and current direction is bigger than 45 degrees, and then allowing velx to be modified while keeping move = false ?
@@twoboxtoofurious That's a good point. I think what happens may be that a NavMeshAgent may never really turn in place, so that case is not triggered when the character is driven by a NavMeshAgent. I think that under manual / keyboard control, the turn-in-place case should work. Just curious, why do your teachers advise against using root motion?
Hi, thanks for your comment. I am working on the next video and should have it uploaded this week. The topic will be waypoints and having a set of NPCs wondering through the environment.
Great tutorial! I was having same issues with the jittering, but after using your example it went away! Thanks a lot. I suspect it has something to do with the way the unity example handles frame smoothing, can anyone confirm / deny? Anyways GJ, your code works better than the unity docs.
All tutorials just show how to move with root animation and navmesh, but the real problem is when the enemy reach the player and attacks with root motion, then can go through navmesh
There are many ways to implement this, with tradeoffs between difficulty and correctness. As I said in the video, this is a simple solution that works in most cases and would be improved with a more complete set of animation clips. If you have a better approach, please go ahead and post it. I and others would be interested in your solution.
I agree. As I said in the video, there is less foot sliding for forward motion. The foot sliding is worse when the NPC turns around, mostly because the animation clips do not include this type of motion, like walking backwards. The video is intended to show the general approach.
What's the point? This hero movement (is sliding) because its not based on root motion (animation not sync with move).
Root motion:
nav.nextPosition = transform.position;
The complexity here is that both the animation system and the navigation system are trying to change the position of the agent, as explained in the video. In OnAnimatorMove() I actually have the reverse of your suggestion to keep the NavMeshAgent and the animated agent at the same position. What I show in the video worked best after a bunch of experiments that I tried, but there may be other good solutions to this problem as well.
Wow, amazing! I was looking for an example of navmesh + animation without jittering, and found it here. Animations are smooth, especially when added more animations to blend tree. please keep doing awesome content like this
Thank you for the nice feedback, and I'm glad the video was helpful. More videos are in the works. :)
Oh man, I spent WEEKS trying to do this, UNTIL I came across your videos! You've saved me TONS of hours of experiments! Thank you so VERY much for your channel! Subscribed & like! Thanks again Sir!!!
I'm glad that the video was helpful!
When I first got into unity I really thought it was gonna be like Legos. Ah, poor naive slightly (6 months) younger me. Been digging for a while to find videos describing the process of merging various pieces of things, and I think this may be the only one on youtube, so thank you for making this. Even if it's not for these exact assets, it gives me an idea of what's needed, and I can play around from there.
That said, if anyone who sees this comment wants to chime in with other great sources of info on the subject, I'd appreciate it greatly. Lol. So many great packages, and so many things, but man, it sure seems like combining parts for a different car. Sure, a Honda fuel pump will work in a Ford, but it takes a loooot of hacking at it.
Thanks for this comment, and I agree there is a lot of expert knowledge required to make all the parts work together!
Found this video today after struggling with animations for weeks. I'm so glad I found this because now, I'm going to hopefully be able to finish my game.
Glad it helped, and good luck with your game!
@@ClockworksGames Thanks a lot. I subscribed. I look forward to seeing more of your content.
@@ClockworksGames One question. I can't seem to get a hold of the Standard Assets animations. Would you say that I can substitute the animations with animations from Mixamo?
@@CodemasterJamal Are you able to get the assets here? assetstore.unity.com/packages/essentials/asset-packs/standard-assets-for-unity-2018-4-32351
@@ClockworksGames I found them in the link you provided. Some of the links have changed, which is why I was confused but, I found the assets eventually.
This is awesome! Thank you!
Glad it was helpful!
AMAZING video this is just what I was looking for.
I have been researching this problem for 2 days now
I'm glad the video was helpful!
This is exactly what I needed -- I was having trouble with "foot sliding."
Glad it was helpful!
It works great! Thank you!
Glad it helped!
Thank you for this! I could not figure out what simple dumb thing I was missing and you nailed all the little things I need. Awesome video!
I'm glad the video was helpful!
Great video! Is it possible for you somehow to share o show all the animation clips. I´d love to see how turn left and right animations were made to work with navmesh. Thanks for the video!
Thanks for the nice comment! All the animation clips are from the Unity Standard Assets which used to be available for free on the Asset Store, but unfortunately are no longer available.
This is exactly what I was looking for. Thanks!
Glad that the video was helpful!
This is very helpful, I am a little confused as to the transform.position = agent.nextPosition bit (I understand what it stops the agent doing) but doesn't it just negate the rootmotion? the character will move as if the it just had the basic nav agent movement?
Thanks for the question. The main movement of the agent is driven by the animation clips in the Update() function. The line that you mentioned, called in OnAnimatorMove() just provides a small correction because the NavMesh agent and the character model would gradually drift apart otherwise.
@@ClockworksGames I believe Cunnah is correct here. agent.updatePosition = false; only stops the transform from being updated by the agent automatically, but the nextPosition will keep simulating to its destination. You correctly use the agent properties to derive animation parameters and let RootMotion take control of the player transform. You also correctly state that this would result in the agent's nextPosition deviating from the animation's derived transform position. When you implement OnAnimatorMove the animation will no longer update the transform directly, so the idea here is to use your animation's positionDelta as input for moving the transform manually with contraints. Your constraint here is just to set the transform back to the agent's nextPosition, bypassing root motion all-together. What you actually want to do is use the animation's positionDelta and override the agent's nextPosition = calculatedPosition (which will apply navmesh boundaries), then you can set the transform position to the agent's nextPosition. The result is you used the initial agent's velocity to set root motion parameters, and root motion velocity to then update the agent's position, then setting the transform to the new agent position to sync them.
@@robu4005 Thanks for this comment. I have been trying to understand what you said in detail. Do you think something in my approach is not correct or, if correct, could have been done better? I am not surprised if there is yet a better approach. As I mentioned in my video, I tried a lot of things, and what I showed is what seemed to have the best results. But there may certainly be opportunities to improve on it. I would like to understand the details of what you are saying. Thanks again!
For a crouch idle and crouch walking animation movement, do we need to create a separate blend tree like the 'Move' or will it be in the same tree?
For crouching movement, I would create a separate blend tree in the same animator controller.
Hey I did it in a similar way myself. Very helpful video for beginners. Kudos
I'm glad the video was helpful!
Sir, thanks for sharing your knowledge.
Thank you for your nice comment! It is my pleasure.
Nice video! worth a sub.
Thanks for the feedback and for the sub!
Great video. This is super helpful!
Thanks, I'm glad the video was helpful!
I used a couple of animations from Mixamo. Weirdly when I automatically calculated the blend values it produced the wrong values. The animation actually moves the character much faster then the animator blend values suggest. I manually figured out the velocities and used those and it works correctly. Whats up with that?
I haven't tried Mixamo animations but would like to understand this better. Can you tell me specifically what animation clips you used?
@@ClockworksGames Sure thing, as I cannot link you the exact animation it is called "Rifle Run" and it is the version where the character is not pointing the rile ahead. They are holding it down and it is moving back and forth. It is the 3rd option when I search for "Rifle Run". Let me know if you want to make sure you have the right one.
@@ChadGatling Ok, I think I've found and downloaded the correct Rifle Run animation. What other animation clips are you blending this with? Are you using Mixamo animations for idle / walk / turn ? (You can also email me at info@clockworks-games.com if you prefer to communicate through direct email.)
Amazing. It is really helpful for me :)
Thank you for the comment!
I didn't need all the controls to move a char in real time because I'm making a tower defense and have enemy AI characters heading toward a goal point. I found a much easier way to do what I needed. I just wanted the animation to move the enemy toward a set goal point so that it would move at the speed of the animation itself rather than being "pushed" along by the navmeshagent comoponent. To accomplish this, I set agent.updatePosition = false and turned root motion on for the walk animation clip. All I needed was an if condition to check when the enemy position was at the goal point, in which case I set the animation controller enabled to false to make the enemy stop. It's that simple.
Thanks for sharing this approach! Do you have any foot sliding in your animation?
@@ClockworksGames In this approach, the forward pace is driven by the root motion of the walk/run clip, so there is no foot sliding. I did get my simplified approach to work under test circumstances, but it turns out that it's not the right way because the navmesh still controls the rotational steering while the forward motion is driven by the root motion of the animation. What can happen is the character will seem to get lost if the navmesh component is not keeping perfect pace with the character. For now I'm using a multiplier for the navmesh speed so that it can provide correct timing of the rotational steering. I'll probably implement the "recommended" approach later in my project.
@@StygianStyle Thanks for describing your approach. There are many ways to do all these things, and it often takes experimentation to find out what will work.
Amazing tutorial. I was just wondering if you're gonna make any future tutorials on Enemy State machine behaviors such as chasing, attacking with the root motion system.
Thanks very much for the nice feedback! I have a roadmap of upcoming videos including NPC / enemy behaviors, senses of different kinds, and associating reactions with senses. I will add some discussion of state machines as well, which will certainly be required.
sub sir that what i was looking for ty
Glad that it could help!
I don't understand what animation to put in the blend tree, I added walking and turn left and turn right but it didnt work
Have you tried the recommended animation clips from the Unity Standard Assets?
@@ClockworksGames No , I just got them off Mixamo. Where could I get unity standard assets from? Sorry in advance if this is a trivial question hahaha
@@michaelgeorge4524 I see that Unity has recently removed their Standard Assets from the Asset Store, unfortunately. I will look for a replacement. Unity has a new "Starter Asset - Third Person Character Controller" which has idle, walk, and run animation clips, but no turning. That could be used, but I will look to see whether there are any free clips available that include turning.
@@brionsarachan4500 yea without a proper set of animations, it doesn't work properly at all. Keep me updated if you have found anything that works please tell me
I was able to get my hands on animations that make it work and just mirrored all the animations to generate turning effects. The bigger problem I have now is that I cannot modulate the speed on the NPC at all. The NPC is constantly running, after applying the code which I know is part of Unity's make the agent follow the animation tutorial, changing agent speed does not do anything anymore. I want to force the patrolling of an area to be slower but it seems to not be possible after making the speed of the agent be animation based somehow
Are you using animations with root motion for the move state or are they only moving in place?
That is the thing I cannot figure out, wether I should move by animation or by agent.
The animations do use root motion. The position of the NavMeshAgent is decoupled from the animated character using agent.updatePosition = false. The agent's calculated next position is used to adjust the parameters of the animator controller to drive the animation which moves the character. There is a small tweak in OnAnimatorMove() that prevents the character and the NavMeshAgent from drifting apart. Let me know if this isn't clear.
@@ClockworksGames Thanks! It took me a lot to wrap my head around using root motion when every teacher all my life has advised me against it, but the system works, and the solution is simple, elegant and beautiful. So I have no complains here.
I have one question though. You set up animations to rotate on place in the animator, but these never seem to get triggered in your project or mine. I'm guessing the 'velx' animator parameter should be modified while keeping move=false to achieve this. How would you go about implementing these?
Maybe check in update if the angle between desiredDirection and current direction is bigger than 45 degrees, and then allowing velx to be modified while keeping move = false ?
@@twoboxtoofurious That's a good point. I think what happens may be that a NavMeshAgent may never really turn in place, so that case is not triggered when the character is driven by a NavMeshAgent. I think that under manual / keyboard control, the turn-in-place case should work. Just curious, why do your teachers advise against using root motion?
You see so nice😄
Hello, great videos. When will you upload the next part?
Hi, thanks for your comment. I am working on the next video and should have it uploaded this week. The topic will be waypoints and having a set of NPCs wondering through the environment.
Great tutorial! I was having same issues with the jittering, but after using your example it went away! Thanks a lot. I suspect it has something to do with the way the unity example handles frame smoothing, can anyone confirm / deny? Anyways GJ, your code works better than the unity docs.
Thanks for the feedback! I'm glad the code worked for you!
Thank you!
You're welcome!
All tutorials just show how to move with root animation and navmesh, but the real problem is when the enemy reach the player and attacks with root motion, then can go through navmesh
Right, this video does not include the case when players / enemies collide / fight, etc. The example shown is just wandering / patrolling behavior.
Great video sir. Thanks a lot. It helps a lot.🙏
Thanks for your comment! I'm glad the video is helpful.
My steps are jittering
If you would like to send me an email at info@clockworks-games.com with more details on what you are doing I will be glad to try to help.
That movement is wrong, it slides, is not the right way to do it, and that code from Unity api is useless
There are many ways to implement this, with tradeoffs between difficulty and correctness. As I said in the video, this is a simple solution that works in most cases and would be improved with a more complete set of animation clips. If you have a better approach, please go ahead and post it. I and others would be interested in your solution.
too much sliding
I agree. As I said in the video, there is less foot sliding for forward motion. The foot sliding is worse when the NPC turns around, mostly because the animation clips do not include this type of motion, like walking backwards. The video is intended to show the general approach.