Hi I’m using the Aron Granberg’s A* project(FREE) for controlling the AI path finding. I’ll write my requirements and how I’m trying to solve them. Please do suggest better ways.
Requirements:
-
Dynamically constructed NPCs which needs to go to a point in 3D space.
-
During the movement of the NPCs there can appear a wall somewhere on the path. So it needs to find another way when it faces the wall.
Solutions:
- I did like the tutorial on the project page. I can instantiate a prefab and it goes to the target.
- Now there is a problem. I have attached the “DynamicGridObstacle” script to the obstacle. So it updates the graph, No problem if the NPC didn’t get instantiated. But in case it does, the NPC gets stuck i.e. It has already computed the path but the obstacle wasn’t there but somewhere it just popped out. To tackle the problem of an obstacle appearing after NPC has left for target I do a seeker.StartPath() for all the NPCs. Is this a good strategy? Help pls
UPDATE:
So I used a NavMeshObstacle property on the obstacle. If I add those obstacles at runtime, the object modifies the path. Do make sure that “carving” is activated for the obstacle so that your navmeshAgent will recompute the path if it encounters this navmeshObstacle.