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 paynechu · Jul 04, 2012 at 05:18 AM · navmeshnavmeshagentlayercost

How NavMesh Cost can slow down NavMeshAgent's speed?

Hi I have a terrain mesh and a water mesh in my scene. I make them in the different layer for Navigation. Terrain mesh in the "default" layer and water mesh in the "water" layer. I set the "water" layer's cost to 100. What I want is the "water" layer still can walk through but it should make NavMeshAgent walk slowly if they have no choice need to go through the "water" area. But I dont know how to implement this. How can I get the NavMeshAgent's layer cost for current position? How to determine the NavMeshAgent already in the "water" area?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Happy-Zomby · Aug 03, 2015 at 11:48 AM

Hello, I found an answer (thank you to poster!) to a similar problem to the one in this old post somewhere but can't seem to put my hand on the hyperlink... anyway - you can sample the area where your unit is

 var agent : NavMeshAgent;
 
 function Start ()
 {
 agent = GetComponent(NavMeshAgent);
 }
 
 
 function Update ()
 {
 var navHit : NavMeshHit;
 agent.SamplePathPosition (-1, 0.0f, navHit);
 Debug.Log(navHit.mask);
 }

you will get a bitfield result (Built-in areas: 1, 2, 4, user added areas : 8, 16, 32, 64, 128....) which you can use to identify your area index (0, 1, 2, 3 ....) and therefore your area cost / speed / event, etc... hope this helps if you stumble over this old post,

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 nventimiglia · Jul 04, 2012 at 12:53 PM

Create trigger areas to handle the speed modifier

 [RequiredComponenet(typeof(Collider))]
 public class TerrainTrigger : MonoBehaviour{
 
 public float SpeedChange = -100;
 
 OnTriggerEnter(collider Other){
 other.SendMessage("SpeedChange",SpeedChange);
 }
 OnTriggerExit(collider other){
 other.SendMessage("SpeedChange",-SpeedChange);
 }
 }
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 Sirithang · Jul 20, 2012 at 12:29 PM

What about using http://docs.unity3d.com/Documentation/ScriptReference/NavMeshAgent.FindClosestEdge.html

It find the closest Edge from the Agent, and return usefull information in the out parameter (including the mask composed of layers for this edge).

So this should work (untested!):

 NavMeshHit lHit = new NavMeshHit();
 if(FindClosestEdge(out lHit)
 {
     if(lHit.mask & **N**) // where N is the number of the layer to test
     {
        //do here what you'll do for this layer
     }
 }

 
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

How NavMesh Cost can slow down NavMeshAgent's speed? 0 Answers

Why navmesh area cost is not changing agent's path? 0 Answers

NavMeshAgents bumping into stationary agents 1 Answer

Can't get NavMeshAgent move. NavMeshAgent ignores destination property 7 Answers

Navmesh Path is shown even between disconnected regions.? 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