Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 gdennis · Jan 08, 2015 at 03:07 PM · collisionnavmeshnavmeshagent

NPC's bump into eachother trying to reach a position

So I have a player gameobject and 8 NPC gameobjects. Each of these objects have an empty child object called "TalkingPosition", which is dragged a bit in front of the character. Then at "random" points characters (NPCs or the player) walk to eachothers TalkingPositions. Walking is done using a Navmesh with Navmeshagents. (the player is also a navmeshagent)

Now a problem occurs when for example 2 or 3 NPC's walk to let's say the players TalkingPosition. (NOTE that they do not walk concurrent, they walk one after the other. So if one is done walking, the next one starts). So when this happens, one NPC is still on that spot and the other NPC can not reach it (immediately), he 'awkwardly' pushes the other NPC away to try and reach the destination. Sometimes this works, but sometimes he does not reach the destination, and thus the game is stuck waiting endlessly for that one to arrive.

I have 3 different scenes, an outdoor park, an office and a house. In the park a solution could be to move the NPC a small bit from the TalkingPosition, but in the office and the House is not that much room to do this 'safely'.

Can anyone suggest a solution for this matter?

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
1

Answer by Nimred · Jan 08, 2015 at 03:59 PM

If NPC2 walks to the Player with the intent of talking to him, but NPC1 is already there, there's several things you can do:

  1. Just like in real life, NPC2 could join the conversation with Player and NPC1. Which means you can no longer just use a single TalkingPosition, you need several, most likely in a circle to mirror what people do.

  2. Another possibility is to detect NPC2 is coming to talk to the Player, and end the conversation with NPC1 earlier than planned. That could happen in real life if NPC1 does not like NPC2 :)

  3. More hacky, in case you don't need too much detail for your game: you could always loosen the restriction to reach the TalkingPosition. NPC2 can be considered to have arrived at the TalkingPosition if he is right on it OR (is going to it && is less than x meters from it && has collided with another agent). That would look silly but your game would keep running :) That's what you get with hacks.

  4. Also, you have a restriction in your game that only one NPC can move at a time, most likely to avoid doing path avoidance between them. It would make sense to also add a restriction where an NPC cannot even start walking to an agent if that agent is already talking to someone. If each agent is a "Talking resource", then deciding to go talk to one of them locks that resource, until it is unlocked when the conversation ends. That is just like real life too: your friend was talking to someone, you notice the conversation ends and start heading to your friend.

Hope that helps.

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 gdennis · Jan 08, 2015 at 04:25 PM 0
Share

Thank you for the reply. I personally like the 1st approach you gave.

Do you have any idea how to implement something like this? I would then want the NPC2 to choose the circle which is in front of the player (if its free) and otherwise the one closest to him?

avatar image Nimred · Jan 08, 2015 at 06:30 PM 0
Share

You could start by setting up more TalkingPositions as child objects of the agent, and space them the way you like. You will have to decide on a maximum number of them, and if all become occupied (if that can happen in your game), you will still have to use the 2nd or 4th approach as a fallback.

When it's time for NPC2 to move, you need to find out which position to go to. If you had a "TalkingPosition$$anonymous$$anager" script on your agents that contains an array of their TalkingPositions, then you'd also be able to order them the way you like, so that the first in the array is the one NPC1 chooses, NPC2 takes the second, etc.. Then you need to keep track of which ones are in use, with a Dictionary maybe; this way when NPC2 has to move, you can loop through the list and return the first available one. Or take the distance into account and return the closest available one.

You could also generate the talking positions by script, to handle more agents, and make things more organic, but it's a bit more complicated.

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

26 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

Related Questions

Enemies using navmesh are bumping each other through solid objects 1 Answer

Does NavMeshAgent disable a gameObject's collider? 1 Answer

Stop collision of NavMeshAgents 0 Answers

Making a queue for NavMeshAgents 0 Answers

Navmesh agent collision. 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