- Home /
How to make AI walk around ingame built walls?
In my game, one of the mechanics is for the character to be able to build walls and turrets to defend himself from the horde.However, the AI always chooses to always try and traverse the wall, therefore, getting stuck and not being able to move. What I really hope for it to do is to instead look for a different route to the player. Is there a possible way, besides making an updating NavMesh, to be able to fix this? Thanks in advance.
Answer by devondyer · Feb 13, 2018 at 11:16 AM
This solution may slow your performance down quite a bit depending on how many AI controlled objects you have, but you could use Physics.RayCast
to check if there is a collider in front of the object, and if there is, rotate object until there is not one before having it continue along its path. I do not suggest this method, however, as it could lead to a lot of issues performance wise as well as the chance of it not working at all.
Here is a link to the navigation and pathfinding page of the manual.
If you don't want to use navmesh or some other pathfinding solution the above approach is the only possibility. One improvement to the above though is if all your AIs have the same behaviour then you just have to calculate the path once, that would make it a lot cheaper (in fact, this could be useful even if you use some kind of pathfinding).
Compared to the the Updating Nav$$anonymous$$esh, which do you think would be able to run faster? I'd like the game to spawn as much enemies as possible so I'd like to $$anonymous$$imize the necessary system performance.
After a bit more research, I found something called Nav$$anonymous$$esh Obstacles. They create holes in the Nav$$anonymous$$esh, which makes the Agent avoid that spot, effectively accomplishing what you want to do.
Here is the page for Nav$$anonymous$$esh Obstacles in the manual. I think this will solve your problem.
This thing is awesome. It's been the answer to a lot of my problems. Thank you very much.
Your answer
Follow this Question
Related Questions
Can you use NavMesh agents to vary driving/handling model? 0 Answers
NavMesh Agent Obstacle Avoidance Ignore 1 Answer
How to add variables to Components (Nav Mesh Agent)? 0 Answers
Modify NavMeshPath for Tactical FPS (slicing the pie/sweeping maneuver) 0 Answers
Navmesh baking -- Odd results 1 Answer