Combining Unity NavMesh with Humanoid Animation

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • Bring your humanoid characters to life by combining Unity's NavMesh navigation with Mecanim animation. Combining these can be tricky, and this video show you how to do it to create autonomous, AI-driven animated humanoid NPCs for your games and simulations.
    These pages from the Unity Manual are mentioned:
    - Using NavMesh Agent with Other Components - docs.unity3d.c...
    - Coupling Animation with Navigation - docs.unity3d.c... (also shows how to make the Animator Controller)
    The video uses the POLYGON City Pack from the Unity Asset Store: assetstore.uni...
    This video is #6 in the series "Humanoid AI in Unity."
    • Humanoid AI in Unity
    See the Clockworks Games website at clockworks-game...
    Subscribe to the Clockworks Games Facebook group: / gamesfromtheclockworks
    #unityai #gamedevai #unitynavmesh
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 83

  • @tomir3x6
    @tomir3x6 3 ปีที่แล้ว +11

    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

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว +2

      Thank you for the nice feedback, and I'm glad the video was helpful. More videos are in the works. :)

  • @onerimeuse
    @onerimeuse ปีที่แล้ว +2

    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.

    • @ClockworksGames
      @ClockworksGames  ปีที่แล้ว

      Thanks for this comment, and I agree there is a lot of expert knowledge required to make all the parts work together!

  • @katherinebailey7804
    @katherinebailey7804 ปีที่แล้ว +1

    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!!!

  • @Lantertronics
    @Lantertronics 2 ปีที่แล้ว +1

    This is exactly what I needed -- I was having trouble with "foot sliding."

  • @CodemasterJamal
    @CodemasterJamal 2 ปีที่แล้ว +1

    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
      @ClockworksGames  2 ปีที่แล้ว +1

      Glad it helped, and good luck with your game!

    • @CodemasterJamal
      @CodemasterJamal 2 ปีที่แล้ว +1

      @@ClockworksGames Thanks a lot. I subscribed. I look forward to seeing more of your content.

    • @CodemasterJamal
      @CodemasterJamal 2 ปีที่แล้ว

      @@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
      @ClockworksGames  2 ปีที่แล้ว +1

      @@CodemasterJamal Are you able to get the assets here? assetstore.unity.com/packages/essentials/asset-packs/standard-assets-for-unity-2018-4-32351

    • @CodemasterJamal
      @CodemasterJamal 2 ปีที่แล้ว +1

      @@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.

  • @twoboxtoofurious
    @twoboxtoofurious 2 ปีที่แล้ว +2

    AMAZING video this is just what I was looking for.
    I have been researching this problem for 2 days now

  • @joppa-recoiler
    @joppa-recoiler 2 ปีที่แล้ว +2

    This is awesome! Thank you!

  • @hplovecraftmacncheese
    @hplovecraftmacncheese ปีที่แล้ว +1

    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
      @ClockworksGames  ปีที่แล้ว

      Thanks for sharing this approach! Do you have any foot sliding in your animation?

    • @hplovecraftmacncheese
      @hplovecraftmacncheese ปีที่แล้ว +1

      @@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.

    • @ClockworksGames
      @ClockworksGames  ปีที่แล้ว

      @@hplovecraftmacncheese 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.

  • @jenniferroth7824
    @jenniferroth7824 2 ปีที่แล้ว +3

    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!

  • @anshulgupta962
    @anshulgupta962 ปีที่แล้ว +1

    Hey I did it in a similar way myself. Very helpful video for beginners. Kudos

  • @171694
    @171694 3 หลายเดือนก่อน +1

    It works great! Thank you!

  • @Liero2007
    @Liero2007 2 ปีที่แล้ว +1

    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;

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว +1

      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.

  • @teamwasted131
    @teamwasted131 3 ปีที่แล้ว +2

    This is exactly what I was looking for. Thanks!

  • @yangez93
    @yangez93 2 ปีที่แล้ว +1

    Amazing. It is really helpful for me :)

  • @nihil45
    @nihil45 3 ปีที่แล้ว +2

    Sir, thanks for sharing your knowledge.

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      Thank you for your nice comment! It is my pleasure.

  • @nester.1337
    @nester.1337 3 ปีที่แล้ว +2

    Nice video! worth a sub.

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      Thanks for the feedback and for the sub!

  • @barnesnplebian6462
    @barnesnplebian6462 3 ปีที่แล้ว +1

    Great video. This is super helpful!

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      Thanks, I'm glad the video was helpful!

  • @muhammadshahzeb8274
    @muhammadshahzeb8274 3 ปีที่แล้ว +4

    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.

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว +2

      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.

  • @raphaelmitus5209
    @raphaelmitus5209 2 ปีที่แล้ว +1

    You see so nice😄

  • @Cunnah101
    @Cunnah101 2 ปีที่แล้ว +3

    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?

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว +1

      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.

    • @robu4005
      @robu4005 2 ปีที่แล้ว +1

      @@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.

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว +1

      @@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!

  • @dexter_hacks
    @dexter_hacks ปีที่แล้ว +1

    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?

    • @ClockworksGames
      @ClockworksGames  ปีที่แล้ว +1

      For crouching movement, I would create a separate blend tree in the same animator controller.

  • @kirayt249
    @kirayt249 ปีที่แล้ว +1

    sub sir that what i was looking for ty

  • @albertcavs9619
    @albertcavs9619 3 ปีที่แล้ว +1

    Thank you!

  • @Angelo-uv6sv
    @Angelo-uv6sv 3 ปีที่แล้ว +2

    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.

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว

      Thanks for the feedback! I'm glad the code worked for you!

  • @ChadGatling
    @ChadGatling ปีที่แล้ว +1

    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
      @ClockworksGames  ปีที่แล้ว

      I haven't tried Mixamo animations but would like to understand this better. Can you tell me specifically what animation clips you used?

    • @ChadGatling
      @ChadGatling ปีที่แล้ว +1

      @@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.

    • @ClockworksGames
      @ClockworksGames  ปีที่แล้ว

      @@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.)

  • @alifakih9382
    @alifakih9382 3 ปีที่แล้ว +1

    Hello, great videos. When will you upload the next part?

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      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.

  • @twoboxtoofurious
    @twoboxtoofurious 2 ปีที่แล้ว +1

    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.

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว +2

      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.

    • @twoboxtoofurious
      @twoboxtoofurious 2 ปีที่แล้ว

      @@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 ?

    • @ClockworksGames
      @ClockworksGames  2 ปีที่แล้ว

      @@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?

  • @bharadwajn.k9185
    @bharadwajn.k9185 3 ปีที่แล้ว

    Great video sir. Thanks a lot. It helps a lot.🙏

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      Thanks for your comment! I'm glad the video is helpful.

  • @michaelgeorge4524
    @michaelgeorge4524 ปีที่แล้ว +1

    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

    • @ClockworksGames
      @ClockworksGames  ปีที่แล้ว

      Have you tried the recommended animation clips from the Unity Standard Assets?

    • @michaelgeorge4524
      @michaelgeorge4524 ปีที่แล้ว +1

      @@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

    • @brionsarachan4500
      @brionsarachan4500 ปีที่แล้ว

      @@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.

    • @michaelgeorge4524
      @michaelgeorge4524 ปีที่แล้ว +1

      @@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

    • @michaelgeorge4524
      @michaelgeorge4524 ปีที่แล้ว +2

      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

  • @trashpig
    @trashpig 3 ปีที่แล้ว +1

    Why this video only got 300 views?

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว

      Thanks for your comment! I think there is just so much content on TH-cam it can be challenging to find the audience.

  • @conceptfactory5604
    @conceptfactory5604 3 ปีที่แล้ว

    My steps are jittering

    • @ClockworksGames
      @ClockworksGames  3 ปีที่แล้ว +1

      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.

  • @gasfeesofficial3557
    @gasfeesofficial3557 6 วันที่ผ่านมา

    too much sliding