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
1
Question by gdg · Apr 17, 2018 at 07:37 AM · rigidbodynavmeshagent

Make navmesh agent fall from ledge

I'm looking for a way to make my NPCs fall off a ledge (after being kicked by the player). They use NavMesh Agents for pathfinding.

I tried turning off the navmesh agent while it is being pushed, adding force to the attached rigidbody and re-enabling it a few seconds later. If they land on a surface without navmesh (like an edge) then they warp to the navmesh point directly below and it looks odd or sometimes get stuck in in-accessible areas.

Is there a better way to do this?

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

1 Reply

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

Answer by Harinezumi · Apr 17, 2018 at 09:18 AM

I think the first step should be to detect if the agent landed outside a navmesh. Maybe NavMesh.SamplePosition() can help with that, or maybe NavMeshAgent.FindClosestEdge() (the navmesh API is really bad at handling these situations).
Next, how would you like to handle the situation when the agent has landed outside? I assume you don't want them to return at the closest point on the navmesh, because that is the current behaviour. What if they were killed, e.g. fallen off a cliff?

Comment
Add comment · Show 3 · 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 gdg · Apr 17, 2018 at 11:21 AM 1
Share

This is applicable only if they are still alive after falling as I disable the navmesh agent once they are dead. Using SamplePosition on the Nav$$anonymous$$esh looks very good. Thanks!

 Nav$$anonymous$$eshHit hit;
                 var sampleResult = Nav$$anonymous$$esh.SamplePosition(transform.position, out hit, navemeshAgent.radius, Nav$$anonymous$$esh.AllAreas);
 
                 if (sampleResult)
                 {
                     transform.position = hit.position;
                     navemeshAgent.enabled = true;
                 }
                 else
                 {
                     Debug.Log("navmesh agent landed outside navmesh, cannot get back in");
                 }

avatar image Harinezumi gdg · Apr 17, 2018 at 11:39 AM 0
Share

Did it work? Then I will convert the comment into an answer, so that others can find it easier.

avatar image gdg Harinezumi · Apr 17, 2018 at 12:20 PM 0
Share

Yes, it worked :)

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

104 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 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 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

How can I pragmatically move a navmesh rigid body when changing scenes? 0 Answers

NavMeshAgent & Collisions / Physics 1 Answer

OnMouseDown not firing if character isn't touching ground 0 Answers

Movement with NavMeshAgent pushes RigidBody 1 Answer

Using Rigidbody and NavMeshAgent at the same time 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