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 kittybum · Sep 08, 2014 at 09:06 PM · collisionrigidbodynavmeshagent

NavMeshAgent & Collisions / Physics

Hi,

I have a enemy unit with a NvaMeshAgent & RigidBody attached. I have disabled Kinematic disabled so I they can collide. When I run in to the enemy units or apply physics to them the NavMeshAgent gets screwed up.

Is there a way to fix this?

Do I have to enable Kinematic and handle the collisions myself?

Thanks in advance.

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 Vuzok · Sep 03, 2016 at 08:52 AM 0
Share

Think I am having the same issue, any chance you found a fix?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by FenixShadow · Feb 17, 2018 at 03:51 PM

First of all, check out this section in the manual about mixing a NavMesh Agent with other components, including a Rigidbody. It provides some good information, including that if you have a NavMesh Agent and non-kinematic Rigidbody on the same game object there will be a race condition and unexpected behavior will result. https://docs.unity3d.com/Manual/nav-MixingComponents.html

One option to still allow for physical forces on the game object with the NavMesh Agent component is to put some script on that object that temporarily disables the NavMesh Agent and sets the Rigidbody to non-kinematic. For example:

 void OnCollisionEnter(Collision collision)
 {
     GetComponent<NavMeshAgent>().enabled = false;
     GetComponent<Rigidbody>().isKinematic = false;
 }


That will temporarily prevent the NavMesh Agent from trying to move the object while it's being moved by physics forces. However, if you do this, you have to have some way in which to reenable the NavMesh Agent and set the Rigidbody back to kinematic when you are ready for the NavMesh Agent to take control again. I've used a simple timer to give the collision force some time to resolve before giving control back to the NavMesh Agent. This works better with predictable collisions in which you know for about how long the physical forces should have control.

 bool isPhysical;
 float knockbackTime = 1;
 float knockbackCooldown;
 
 void Update()
 {
     if (isPhysical)
     {
         // Add the time since the last Update
         knockbackCooldown += Time.deltaTime;
         if (knockbackCooldown > knockbackTime)
         {
             GetComponent<NavMeshAgent>().enabled = true;
             GetComponent<Rigidbody>().isKinematic = true;
 
             isPhysical = false;
             knockbackCooldown = 0;
         }
     }
 }


Another method that @ChazBass suggested on Reddit is creating the force manually at the time of the collision and then lerping it down to zero before restoring control to the NavMesh Agent. A similar approach, but one which gives you a little more control over the force applied to the object and the point at which you restore control to the NavMesh Agent.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to check for collison with a navmeshagent 0 Answers

Is it ok to move objects with CharacterControllers not through their CharacterController and without adding a kinematic Rigidbody? 1 Answer

Why can't my enemies walk up an incline? 1 Answer

Why doesn't this script work?? Please help.. 1 Answer

Box Colider not working properly 1 Answer


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