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 /
  • Help Room /
avatar image
0
Question by 2-Zons · Nov 24, 2015 at 10:38 PM · networkingnavmeshnavmeshagentnavigation

Off Mesh Link - Limiting access to certain agents

In my game I have dynamically created Nav Mesh agents that wander around the map. There are doors on the map which I am using Off Mesh Links for. Is there a way I could have these off mesh links only accessible to certain agents. Is this possible? Do I need to use an Obstacle?

Any help is greatly appreciated.

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

2 Replies

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

Answer by CraigGraff · Nov 25, 2015 at 10:05 AM

@2-Zons You can just set the navigation area of the Off Mesh links to some custom navigation areas (added in the Areas tab of the Navigation panel). Then use something like the following code to set the area mask of each agent that is allowed to travel through a gate.

 using UnityEngine;
 
 public enum Gate {Red=3, Green, Blue}
 
 public class AgentAreaMaskExample : MonoBehaviour
 {
     NavMeshAgent agent;
     void setGateAllowed(Gate gate, bool allowed)
     {
         if (allowed)
             // set bit on
             agent.areaMask |= 1 << (int)gate;
         else
             // set bit off
             agent.areaMask &= ~(1 << (int)gate);
     }
 
     void Start()
     {
         agent = GetComponent<NavMeshAgent>();
         setGateAllowed(Gate.Green, true);
     }
 }
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 2-Zons · Nov 25, 2015 at 03:30 PM 0
Share

Thank you for the reply. Can those areas be dynamically assigned at runtime? The doors I am using are placed by the player.

avatar image CraigGraff 2-Zons · Nov 25, 2015 at 04:34 PM 0
Share

@2-Zons Yes, with something like:

 Off$$anonymous$$eshLink link = GetComponent<Off$$anonymous$$eshLink>();
 
 link.area = 3; // set link to only allow characters if they can traverse area 3



avatar image 2-Zons · Nov 26, 2015 at 12:47 AM 0
Share

This looks like it will do the trick. As soon as I can get it implemented in my project and test it I will accept this answer as correct. There seem to be a lot of people following this question, so I don't want to accept the answer until I am certain it works as desired.

avatar image
0

Answer by 2-Zons · Nov 27, 2015 at 04:01 AM

This worked just as described. One thing that I needed to be careful with was the doors are prefab's and and the enter and exit tied to child game objects. The doors needed placed so that the enter and exit transforms are within a certain tolerance of the nav mesh surface. if placed too high they wont function properly. Thanks @CraigGraff

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

45 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

Related Questions

Navigation 0 Answers

Farthest Reachable Destination 0 Answers

Networked movement using navmesh agent 0 Answers

for nav mesh agent, why is it that the base offset is 1 instead of 0 as default and why is setting it to 0 make the cylinder colider move down? 0 Answers

Navmesh agent passing through obstacles (path goes under navmesh) 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