Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by philwinkel · Nov 23, 2014 at 08:37 PM · movementmecanimnavmeshagentroot motion

NavMeshAgent using Root Motion for move speed?

I am using NavMeshAgent to control AI character movement. I'd like to configure it in such a way that the NavMeshAgent controls rotation and turning the character, but the root motion of my movement animations should control the speed of the character moving forward.

Is this possible? Are there any examples anywhere that I could take a look at?

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlexHJohnstone · Oct 11, 2015 at 12:33 PM 0
Share

@philwinkel Thanks for this!

4 Replies

· Add your reply
  • Sort: 
avatar image
22
Best Answer

Answer by philwinkel · Nov 30, 2014 at 09:21 PM

Going to answer my own question in case anyone else runs into this issue, since i'm such a nice person...

Apparently mecanim root motion + NavMeshAgent can be done, there is an example in the Mecanim Examples asset that is on the asset store. In a nutshell you place a script on the same GameObject as the Animator, and that script should have the following method:

 void OnAnimatorMove

Inside OnAnimatorMove, you can get the root movement from mecanim root motion and then apply it to the NavMeshAgent's velocity like this:

 void OnAnimatorMove()
 {
     _agent.velocity = _anim.deltaPosition / Time.deltaTime;
 }

So, between Mecanim and NavMeshAgent, a lot is possible, although it takes some scripting and clever use of Mecanim parameters (and StateMachineBehaviours in Unity 5 help a lot).

Look inside the "NavMeshExample" scene of these assets for more examples: https://www.assetstore.unity3d.com/en/#!/content/5328

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LUKS123456 · Aug 12, 2016 at 10:11 PM 1
Share

This make the Nav$$anonymous$$eshAgent speed based in the root motion, but now my character is running in circles. I don't know what is wrong. =(

avatar image
4

Answer by indieman · Jul 08, 2016 at 11:27 AM

Assuming you want the movement of your character to be controlled by the animator (root motion), the simplest way is to update the NavMeshAgent's position to match the character's position:

 void Update()
 {
 NavMeshAgent.updatePosition = false;
 NavMeshAgent.updateRotation = true;
 
 NavMeshAgent.nextPosition = transform.position;
 }

The result is that every time your character changes position, the NavMeshAgent is being pulled onto the character's new position, regardless of the NavMeshAgent's speed (which should be set to exceed the maximum velocity.magnitude of the animation).

I hope this helps.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image me2000 · Sep 04, 2016 at 11:01 AM 0
Share

Turning off updatePosition, also stops updating the rotation. Not sure if bug or intended but it's very annoying!

avatar image
3

Answer by str3lok · Apr 29, 2016 at 08:33 AM

In block "OnAnimatorMove" it is necessary to change the speed of movement (instead of motion vector):

 void OnAnimatorMove()
  {
      _agent.speed = _animator.deltaPosition / Time.deltaTime;
  }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Azzgil · Apr 08, 2017 at 10:26 AM 0
Share

Yeah, that's the thing! Thank you kindly, dude

avatar image Azzgil · Apr 08, 2017 at 06:28 PM 2
Share

But actually you must rewrite it as:

 void OnAnimator$$anonymous$$ove()
   {
       _agent.speed = (_animator.deltaPosition / Time.deltaTime).magnitude;
   }

avatar image
2

Answer by Jordan104 · Oct 11, 2015 at 12:01 PM

I've found that if you set the nav mesh agent speed to 0.1 and set apply root motion to true on the animator component that it does the trick.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hannibal_Leo · Jan 27, 2021 at 03:58 AM 0
Share

You can set the speed to 0, problem is that the nav$$anonymous$$esh "velocity" and "desiredVelocity" will be set to (0,0,0) but you still can read out "nextPosition", "steeringTarget", as well as the Nav$$anonymous$$eshPath will all it's points - which you can then use to adjust your animator parameters.

avatar image astanid · May 08, 2021 at 10:30 AM 0
Share

That's an interesting trick. And it 'kinda' works, but this completely breaks NavAgent collision detection :( Seems like there's no way to make NavAgent to avoid collisions with each other using root motion :(

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim: 2D Blend Trees, Unable to Compute Positions. 0 Answers

Mecanim Root Motion -- Not Moving Forward? 1 Answer

switching between Motion matching and animation files 0 Answers

Navmesh orthogonal movement 0 Answers

Root Motion and Navmesh Agent 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges