Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by rtwiss · Oct 23, 2015 at 03:28 PM · navmeshnavmeshagentdestination

Navmeshagent Spins on the Spot when Close to Destination

I have a navmeshagent, and a set of destinations that the agent walks between. The agent always will reach the destination eventually, but sometimes when it gets pretty close, it will spin for up to 30 seconds before actually getting to the destination.

I have a feeling it's because the agent can't reach the destination exactly on the first time, so it's overshooting by a little bit every time, and that causes the spinning.

Any suggestions on how to fix this? I've tried tweaking the navmeshagent settings, but have had no luck.

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 CarterG81 · Oct 09, 2017 at 09:15 PM 0
Share

http://answers.unity3d.com/questions/1282690/how-to-prevent-navmesh-agent-from-overshooting-des.html

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by skprsr · Oct 23, 2015 at 06:06 PM

You can try increasing the Stopping Distance of your NavMeshAgent from the inspector...

Sometime it can't calculate Stopping Distance exact 0 as remaining and then it start to make misbehave.
So make Stopping Distance something large enough.

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
avatar image
0

Answer by howong · Mar 30, 2018 at 01:33 AM

Thanks all. I tried increasing the stopping distance, but even at low values like 0.1, I saw the issue still happen occasionally. I also tried the link supplied by CarterG81, but the solution makes the agent move while ignoring acceleration (it uses the max speed directly), and also the agent doesn't move in a curved fashion - the agent normally (when updatePosition is true) moves on a curve toward their steering target based on velocity, acceleration, and angular speed. I found that to preserve the acceleration (mostly) and curved movement (mostly), I move the agent straight toward the destination on the last stretch (on the last steering target). This retains the curved movement for the corners in between, then when the destination is the last "corner," we move straight toward it (the agent still rotates as they would when moving in a curved fashion, which in my opinion is better than an abrupt change in rotation, but I suppose one could make some changes to do an abrupt rotation change if they wanted). The desiredVelocity will always form a straight line toward the steeringTarget (as dictated by the path). This means though that there won't be any deceleration as the agent nears the destination and no acceleration if going straight from rest, so I'm working on fixing those aspects now. This is for the case that we don't use animation root motion for movement. I'm still looking into the root motion case.

Code:


            // Avoid circling the destination
            if (agent.hasPath && (agent.steeringTarget == agent.destination))
            {
                Debug.Log ("Has path and steering target is destination");
                if (Mathf.Approximately (agent.velocity.magnitude, 0))
                {
                    Debug.Log ("Velocity was zero, so using desired velocity (max speed)");
                    agent.velocity = agent.desiredVelocity;
                }
                else
                {
                    Debug.Log ("Velocity was non-zero, so using desired velocity direction with velocity magnitude");
                    agent.velocity = (agent.desiredVelocity.normalized * agent.velocity.magnitude);
                }
            }

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
avatar image
0

Answer by BrainSlugs83 · Apr 09, 2020 at 07:08 AM

I just tell it to stop if it gets close enough (note that you have to set .isStopped = false the next time you call .SetDestination):

 if ((this.transform.position - agent.destination).magnitude < .1f)
 {
     Agent.isStopped = true;
 }

I have no idea why this is necessary, but Stopping Distance just didn't work for me. -- Might be because I'm using a RigidBody? -- But for whatever reason. I ended up setting Stopping Distance to 0, and manually checking for myself using the above code.

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

7 People are following this question.

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

Related Questions

A lot of navmesh agents affects ai accuracy 0 Answers

Problem with Navmesh 1 Answer

100+ navmesh agents are not accurate 0 Answers

How to check if my player agent is at the end of the position 2 Answers

How do I stop NavMeshAgents fighting over their exact destination? 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