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
0
Question by Shkarface-Noori · Nov 22, 2013 at 11:17 AM · aicontrollermecanimnavmeshagent

NavMeshAgent With Mecanim

Hi...What i want to do is to create a Mecanim Controller which is driving by a NavMeshAgent AI... and sending both speed and angle from the AI to the Mecanim Controller.... i have tried the learning project "Stealth" to make the script...but when the player is near the object that i want it to follow.... the player will bounce from x to z random points then stops.... this also happens when the object gets a new longer distance and the player starts bouncing again and move to the object...any idea?

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 infinitypbr · Nov 22, 2013 at 04:50 PM 0
Share

Sounds like a scripting problem, can you post your code?

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by infinitypbr · Nov 29, 2013 at 08:00 PM

http://docs.unity3d.com/Documentation/ScriptReference/NavMeshAgent-desiredVelocity.html

Don't let the NavMeshAgent control movement. Instead pass this variable to mecanim to allow root motion to work/move the object.

Comment
Add comment · Show 5 · 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 Aranhawebs · Nov 29, 2013 at 09:09 PM 0
Share

Here, i use:

 void OnAnimator$$anonymous$$ove () {
     anim.rootPosition = navAgent.desiredVelocity;
 }
avatar image infinitypbr · Nov 29, 2013 at 09:22 PM 0
Share

Never used OnAnimator$$anonymous$$ove myself, but it looks like that's post-movement, and if I'm not mistaken, you're trying to tell $$anonymous$$ecanim how fast to move based on the Nav$$anonymous$$eshAgent?

So when, for instance, player is within the range of the enemy, enemy's Nav$$anonymous$$esh is turned to active, and then the desiredVelocity is sent to mecanim as a float variable (likely called "velocity" if you follow the standard conventions).

Root motion takes hold from that, moving your character forward.

avatar image infinitypbr · Nov 29, 2013 at 09:23 PM 0
Share

Here's some code I use -- you'll have to fill in the blanks, but this runs if the enemy is supposed to be moving, and gently increases the velocity.

[Note: desiredDistance does not refer to physical distance, but rather float based on the desiredVelocity, which itself is a Vector3 and can't be passed into $$anonymous$$ecanim]

  var desiredDistance = Vector3.Distance(charNav.desiredVelocity, Vector3(0,0,0));
  currentVelocity = $$anonymous$$athf.Lerp(lastVelocity, desiredDistance, (Time.deltaTime * 2));
  lastVelocity = currentVelocity;
  charAnimator.SetFloat("velocity", lastVelocity);        // Pass currentVelocity to Animator
avatar image Shkarface-Noori · May 13, 2014 at 07:12 PM 0
Share

But i want the Animations to set the velocity of the AI.. what if i have some sort of a zombie walk? when speed is like : 1>>0.1>>0.4>>1>>0 ... all in the root motion... i want the Nav$$anonymous$$esh to be driven by the Root$$anonymous$$otion.

avatar image Jaqal · Aug 07, 2014 at 02:42 AM 0
Share

Has anyone figured out a way to do this yet? I have been banging my head for days trying to get animations to control velocity with mechanim and navmesh.

avatar image
1

Answer by Aranhawebs · Nov 25, 2013 at 10:09 PM

That happened to me too, i guess is because the animation, that moves forward on the axis, so the character goes straight from the point, and try to go back and goes straight several times.

If you disable the animation, and let the agent handle the movement and rotation, this doesn't happen. I'm trying to figure out the best way to use the agent with the mecanism too, if you know something let me know. =)

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 Shkarface-Noori · Nov 29, 2013 at 07:09 PM 0
Share

that's right.....pm me if you got anything new too

avatar image
0

Answer by Robacks · Mar 18, 2014 at 06:17 PM

Or try to let the NavMeshAgend controll the position but dont apply root motion from your animations.

 var animator = GetComponent<Animator>();
 animator.applyRootMotion = false;
 

You may also have a look into your AnimationClips you are using and, set each Root Transformation setting to use "Original" positions from your animations. See here.

Doing so for my animations had solved this kind of trouble.

(A little bit late but it might help someone else ;) )

Comment
Add comment · 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

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

19 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

Related Questions

How would I use Mecanim to holster or draw a weapon? (C#) 1 Answer

Why isn't my enemy pausing in between waypoints? C# 1 Answer

How do I limit the path of a NavMeshAgent? 0 Answers

Animator component prevents NavMeshAgent from disabling/enabling dynamically 0 Answers

My NavMeshAgent doesn't move at all!,Why my NavMeshAgent doesn't move at all? 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