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.

97832-untitled3.png
97833-untitled2.png

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).
  1. 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?

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.

@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.