Combining Unity NavMesh with Humanoid Animation

Поделиться
HTML-код
  • Опубликовано: 17 дек 2024

Комментарии • 90

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

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

  • @katherinebailey7804
    @katherinebailey7804 2 года назад +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!!!

  • @onerimeuse
    @onerimeuse 2 года назад +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  2 года назад

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

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

  • @joppa-recoiler
    @joppa-recoiler 3 года назад +2

    This is awesome! Thank you!

  • @twoboxtoofurious
    @twoboxtoofurious 3 года назад +2

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

  • @Lantertronics
    @Lantertronics 2 года назад +1

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

  • @171694
    @171694 6 месяцев назад +1

    It works great! Thank you!

  • @jenniferroth7824
    @jenniferroth7824 3 года назад +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!

  • @pgpress
    @pgpress 2 месяца назад +1

    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!

    • @ClockworksGames
      @ClockworksGames  2 месяца назад

      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.

  • @teamwasted131
    @teamwasted131 3 года назад +2

    This is exactly what I was looking for. Thanks!

  • @Cunnah101
    @Cunnah101 3 года назад +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  3 года назад +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.

  • @anshulgupta962
    @anshulgupta962 Год назад +1

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

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

  • @barnesnplebian6462
    @barnesnplebian6462 3 года назад +1

    Great video. This is super helpful!

  • @ChadGatling
    @ChadGatling 2 года назад +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  2 года назад

      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 2 года назад +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  2 года назад

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

  • @yangez93
    @yangez93 2 года назад +1

    Amazing. It is really helpful for me :)

  • @StygianStyle
    @StygianStyle 2 года назад +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  2 года назад

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

    • @StygianStyle
      @StygianStyle 2 года назад +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  2 года назад

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

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

  • @kirayt249
    @kirayt249 2 года назад +1

    sub sir that what i was looking for ty

  • @michaelgeorge4524
    @michaelgeorge4524 2 года назад +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  2 года назад

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

    • @michaelgeorge4524
      @michaelgeorge4524 2 года назад +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 2 года назад

      @@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 2 года назад +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 года назад +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

  • @twoboxtoofurious
    @twoboxtoofurious 3 года назад +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  3 года назад +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 3 года назад

      @@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  3 года назад

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

  • @raphaelmitus5209
    @raphaelmitus5209 2 года назад +1

    You see so nice😄

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

  • @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  3 года назад

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

  • @albertcavs9619
    @albertcavs9619 3 года назад +1

    Thank you!

  • @MkGyver-m8c
    @MkGyver-m8c 2 месяца назад

    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

    • @ClockworksGames
      @ClockworksGames  2 месяца назад

      Right, this video does not include the case when players / enemies collide / fight, etc. The example shown is just wandering / patrolling behavior.

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

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

  • @MkGyver-m8c
    @MkGyver-m8c 2 месяца назад

    That movement is wrong, it slides, is not the right way to do it, and that code from Unity api is useless

    • @ClockworksGames
      @ClockworksGames  2 месяца назад

      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.

  • @gasfeesofficial3557
    @gasfeesofficial3557 3 месяца назад

    too much sliding

    • @ClockworksGames
      @ClockworksGames  2 месяца назад

      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.