- Home /
How do I make the NavMeshAgent more stupider?
It should be simple but I have no idea how to do it.
I have a player character that moves with the NavMeshAgent, and I have a system where my character can roll, this also uses the NavMeshAgent because it works with the system I have set up already. On open ground this works exactly as I want it to, but when I roll towards an obstacle such as a wall without enough space to actually roll, what should happen is my character simply smashes his face against the wall like a dumdum. Instead, he tries to go around the wall.
Simply put, I would like to be able to temporarily turn off a navAgent's obstacle avoidance entirely.
How does do?
Answer by AmiraKing · Apr 29 at 07:18 AM
Hello,
Thanks for asking this because, I faced similar kind of issue last time, I am still searching for some proper solution Same issue still no fix to this. My Insite Sign In This is probably a bizarre request - I would like to have my agents not knowing the entire map. For example, a wolf sees you across an iron bar gate, if using regular navmeshagent on the wolf, he would (very intelligently) run a mile around the walls and find a way to you and attack you. It's not very realistic. Ideally the wolf would not know how to get to you, so he just run to the iron gate (of course, bypassing whatever obstacles between him and the gate) and howl at you or something.
It would be nice if there are two things that can be done by navmeshagent:
Check if the calculated path is too long (this can be done using "remainingDistance")
If it is too long, calculate a closest reachable location (i.e. right behind the iron gate)
I'm not sure how #2 can be done. I know there are navmesh areas, and area mask, is it possible to calculate path only within a certain area so as a last resort the agent will go to the closest reachable location?
Please Help Us
Thank you
Raycast to your target to see if there is an object in the way.
If the Raycast hits something and that something is tagged "Structure", get the RaycastHit.point from that Raycast. (I use structure it doesn't have to be that word)
make your navAgent for the wolf go to that point, instead of to the player.
since that point is inside the fence, wolfy boi will go to the nearest point it can get to. (which means it will be on it's side of the fence)
repeat in update function, or possibly on a tick system if you don't want to run a navAgent.SetDestination every frame. (since that can be a fairly expensive call).
That's essentially what I did to fix my problem. It feels bad because you are building a fix to remove a feature, when it would be better to just have some way to remove the feature, but there it is. EDIT formatting
Your answer
Follow this Question
Related Questions
updateUpAxis code error 1 Answer
ontriggerenter multiple call problem 0 Answers
NavMeshSurface at runtime - agent not on surface? 2 Answers
Navmesh two agents going to the same possition 0 Answers
Getting a Movable Area from NavMesh 0 Answers