OnPathComplete (Path _p) - if (_p.error): sometimes too hasty

Hey!
Iam currently trying to implement the A* pathfinding into my maze game:

but sometimes the path gets marked as true, even if the path is not completed:

here is my current implementation: http://pastebin.com/TxCe4a1e
the important line is, i guess, at line 275:

public virtual void OnPathComplete (Path _p) {
      if (_p.error) {
             Path =false;
             Debug.Log("Target could not be reached");
      } else {
            Path =true;
             Debug.Log("Target could be reached");
      }

i think the ray slips threw the rotated piece, cause it always happens when i rotate more parts pretty fast

is there anything possible like. Path _p has no error, so Path=true, but lets test it again half a second later to check if its really really true, if not, continue the checking stuff. something like a double check?

What kind of graph are you using? If I were you, I would make a new graph derived from PointGraph. Then I would override the Scan method (think it is called something else actually; check the docs) to update the nodes based on your maze’s tiles. You know which pieces are connected to each other properly, so you can use that info to update the graph.

Each time the player rotates a tile, just re-scan the graph.

It is actually surprisingly easy to write a new graph for this. I have had to do this twice, and it never took me more than a few hours.

Hey,
Iam using the grid graph. But gonna try the point graph. Thanks for the hint.
I think the biggest problem is that you can rotate a piece while the other is still rotating. But turning off the rotation as long as one piece is rotating would slow down the whole game experience somehow?

Hi

If you want to avoid most custom code like creating a new graph, a simple solution is to separate the rotation of the mesh and the colliders. So when a player clicks on a tile, the colliders instantly rotate to the correct position and the graph is updated, however the actual mesh rotates more slowly over several frames for aesthetic purposes (like it does now).

1 Like

Thats a briliant idea aron. Thanks :slight_smile:

1 Like