- Home /
Problem getting player to switch navmesh layers
Alright so I have a character and my navmesh is set up into two layers. Default which the player can always walk on and phase (user layer 0) which the player cannot walk on usually. What I want to do is let the player use an ability that allows him to walk on the phase areas of the navmesh. There doesn't seem to be any documentation on how to do this anywhere so I have come here to see if you guys know the answer. The closest I got was:
Agent.walkableMask.Equals(9);
Agent is a reference to the players NavMeshAgent. From what I understand this should let the player walk on the default layer and user layer 0 (phase) but it has no effect at all and I get no error messages after compiling or in game. What's the correct way to do this?
Answer by HarshadK · Oct 20, 2014 at 06:53 AM
You need to provide a proper layer number as input.
Read the answer to this question: NavMesh WalkableMask
This will tell you how to select the proper layer to provide as input to the WalkableMask.
You set is as:
Agent.walkableMask = 9;
Setting it to
Agent.walkableMask.Equals(9);
will just make a comparison and not actually set it.
Ahh yes that is actually where I got my number 9 from :P Problem is I have the number I just don't know where to put it and the line I put in the OP is as close as I got but that has no effect. I pretty much just don't know the right syntax for the function I'm trying to call.
You set is as:
Agent.walkable$$anonymous$$ask = 9;
Setting it to
Agent.walkable$$anonymous$$ask.Equals(9);
will just make a comparison and not actually set it.
Thank you so much! I was stuck on that for like 2 days. Glad I can finally move on :D
Your answer
Follow this Question
Related Questions
How to make enemy AI with NavMesh 2 Answers
All my NavMeshAgents are tilted 1 Answer
Move gameobjects in the direction the player is facing 1 Answer
Root motion handled by script. How to still use root motion with disabled navmesh agent? 0 Answers
PhotonNetwork.IsClient, how to set tags for players? 2 Answers