- Home /
Artificial intelligence - Find way through changing path
The NPC starts off at the yellow circle and the goal is for it to make all its way to the green circle.
The map consists of platforms formed by 4 circles of the same color (the yellow and green where colored differently to make it clear they are the starting point and the destination, respectively). A platform can be rotated in angles of 90 degrees counter-clockwise. The little black squares in the map are bridges that connect platforms. The NPC can walk across them to move from one platform to another.
The NPC can't move from one circle to another (not event circles that are part of the same platform) unless there's a bridge connecting them.
So the 2 only movements are: rotate a platform (adjacent circles of same color) and walk across a bridge.
The NavMesh is formed by all circles and bridges.
The challenge is what path the NPC has to take, given that the destination might not be right away reachable since platforms have to be rotated for the NPC to be able to move forward.
The way I thought (but couldn't make it work yet) was to:
1) At the yellow circle Call "SetDestination" passing the position of the green circle.
2) Call CalculatePath:
if the Pathstatus is "Complete", then he can directly walk to destination.
if the Pathstatus is "Partial" then I know that the platform has to be rotated. When platform is rotated, the NPC might start moving (if there's a bridge to the adjacent platform) reaching eventually the destination (done), or getting stuck again (moment to rotate platform again).
3) If NPC hasn't reached destination, go back to 2)
Maybe I'm overcomplicating it.
Is this the right way to go? Is it more complicated than I think?
Theres always a path unless you don't alternate red blue red blue as you have in the image.
Create an empty moves list - push an int that is the number of times the current group must rotate until he touches the next group along with an int representing how much the next group will need to rotate til he can move on. Theres not even that many cases so you could easily get a $$anonymous$$imum moves solution as well by brute force.
I might be missing the rules here i seems pretty simple. You said he can only rotate things of the same color.. but then you said at the beginning he rotates the first four so I'm thinking he rotates groups of four that are the same color. ins$$anonymous$$d of 2 and 2 from different groups or all groups of the same color at once.
Thanks @Jwizard93 I edited the original post to clarify.
Answer by NorthStar79 · Jul 17, 2017 at 06:14 AM
you can not rotate baked nav mesh. so eighter you need to use some another pathfinding solutions (like A* asset on asset store) or not use a navmesh at all and try a workaround by firing lots of raycast or something idk.
Answer by kkrac · Jul 17, 2017 at 01:28 PM
@NorthStar79 I did a small "hack" for that: I marked the circles as static, baked the mesh, and then unmarked the "static" check of the circles so that they can move. Since there's always a circle in the position where a part of the mesh is, it works Ok.
If it happens I forgot to add a circle to the path when building the scene, I have to mark all circles again as static after adding the circle I missed, and re-bake the mesh. Not that big of a hassle since I just need to mark the circle's parent empty gameObject and not go one by one.
Maybe not the best solution, but it did it's job for what I was looking for.
Your answer
Follow this Question
Related Questions
Use Fog of War to Restrict NavMesh Per-Agent 0 Answers
Horde of NavMeshAgents - stops to recalculate path. 4 Answers
How do I fix two NavMeshAgents fighting for the same position? 1 Answer
Recentering an infinite world that has a NavMesh. 0 Answers
How to check if Navmesh finished baking realtime ( in playmode ) ? 1 Answer