Character Moves To Wrong Point

Hi everybody,

I’m working on a 2D Grid Graph. As in the picture my character moves from c1 point to c2 directly inside the wall. I use the code below to check if is path possible and it returns true.

    GraphNode a = AstarPath.active.GetNearest (transform.position, NNConstraint.Default ).node;

	GraphNode b = AstarPath.active.GetNearest ( targetPos, NNConstraint.Default ).node;

	return PathUtilities.IsPathPossible (a, b);

I have tried changing grid size and node counts but nothing works. Why is she behaving like that ? Do you have any suggestion?

Hey,

Just to be sure can you debug out the transform.position / targetPos and make sure something isn’t where it wasn’t supposed to be.

I imagine IsPathPossible checks the areas of the two graphs, but I can hop in an check. what version do you have?

@PaulUsul Everything is OK about positions. In usual game flow character draws correct paths and move on them. Rarely it moves like in the screenshot. The points are in different graph color sections. My version is 4.0.11.

I checked in PathUtilities.IsPathPossible and it checks if both nodes are walkable and if their areas are the same.
I’d put in a debug.log just above the return that debug’s out everything then reproduce the bug and it should be apparent what’s wrong.

It could be that what you are seeing move and what the script is on has an offset through different pivot points or if the editor accidentally got set to center not pivot.

@aykutyilmaz
Which movement script are you using?
The built-in movement scripts should never move from c1 to c2 through unwalkable nodes unless you have set the Seeker->StartEndModifier->End Point field to ‘Original’ for some reason (the default is ClosestOnNode).

As @PaulUsul says, the IsPathPossible call only checks if there exists a valid path between those 2 nodes. In this case it should return false however since c1 is in a different area from c2 (their colors are different in the scene view). Try to draw the points that the GetNearest method returns using e.g Debug.DrawRay((Vector3)node.position, Vector3.forward, Color.red, 10);

@PaulUsul thanks for your advice. I couldn’t find anything wrong about positions or pivot points. System works nice and correct %99.9 of the time. When this bug happens positions are also true. Only thing wrong is the AI thinks it is a valid path.

@aron_granberg I use AILerp script. I checked the StartEndModifier they are set to ClosestOnNode. DrawRay function prints line near or on the AI and the target. I don’t know what should I understand from that. I changed nodes size and width, depth parameters. Everything is fine since then.

Sorry for late reply, i tried your methods when you wrote but I forgot to write back to you :slight_smile: It was a very busy week. I will keep you updated if something goes wrong. Thanks for now :slight_smile: