- Home /
Unity Navagation Ground Mapping
ok, I normally answer questions, but today I'm the one asking them. I know how unity has different layers you can apply to the Navigation map, which NavAgents use to plan out their paths.... always going the easiest way possible. And that you can assign weights to these layers.... HOWEVER If you tell a troop to move to an area that isn't recommended, the agent will still move there if possible... however, this troop will move through a 'mud region, 20' as fast as 'pathway, 0.2'. Is there a way to slow down the agent depending on the weight of the current layer it is in?
help.... anyone have any idea? don't need a full response, so IDEAS are welcome.
$$anonymous$$aybe you can use SamplePathPosition on your agents with a really short distance to find out which area they are in, then adjust their speed accordingly.
hmmm... that's possible. I might have a hard time keeping tack of my original target, much less update that target... Thank you for the suggestion, do you know if it is possible to use SamplePathPosition without changing the target?
Answer by bennett_apps · Mar 05, 2019 at 01:32 AM
just bring down the agent's speed if you sense you're in the mud. Something like:
NavMeshHit hit;
Navmesh.SamplePosition (transform.position, out hit, Mathf.Infinity, Physics.AllLayers);
if (hit.areaMask == mudMask) {
agent.speed = slowSpeed;
} else {
agent.speed = normalSpeed;
}
Your answer
Follow this Question
Related Questions
Duplicated NavMesh Agents not moving 0 Answers
NavMesh agent snaps to wrong mesh 0 Answers
Nav mesh agent position 1 Answer
Removing 100ms Delay in NavMeshAgent moving to destination? 1 Answer