Pathfinding can not find the path

I’m sorry but in the game I’m making, the pathfinder can not find the path
-Pathfinder : the small black dot at left side

-The target (player): big black dot at right side

-The all black wall: ostacles

If I move the player more near to pathfinder, it can find the way, but for some positions as attachment, it can not find the way.
How to do it? Pls help me

How are you moving the object? Is the target being placed or does it move? A screenshot of the events that move the target and player would help.

This post might help. It contains more details and images of the settings.

https://forum.gdevelop.io/t/make-pathfinding-collision-less-choppy/60067/7?u=keith_1357

This illustrates how the pathfinder works.

The dots represent the grid that the behavior uses to find a path.The line is the path the object takes. It helps if the objects that move have centered origin points.

You can see how when the object’s origin point is in the top corner that the object would collide with the wall so it wouldn’t be able to find a valid path. But when the point is in the center, it’s perfectly centered.

The yellow dot is the origin point.
Screenshot_20241105_082141_Chrome

It helps if the objects are setup using a grid of the same size as the pathfinder behavior’s grid. To center the pathfinder grid it helps to have an offset that is half the size of the grid spacing. If the grids are 32x32 then the offset for the pathfinder would be 16x16.

It sometimes helps if the pathfinder’s allow diagonals is unchecked. It’s under the pathfinder advanced setting.

1 Like

Thank you very much for your help.
My English is not so good, so I will need more time to try your way.
My target is not move, it will stay in same positions in whole scence.
The space between ostacles is much bigger than the pathfinding, and I don’t want a pixel moving.
If the target is more near to the pathfinding, it can find the path and move correctly. But as my photos, it can not find the path.
is it too complicated for path finding? has some limit as how many turns it take or how…
(PS: my ostacle will be randomly placed on the scence so I want to sure that it can find the path unless the target is totally sealed by ostacle)

I use draw pathfinder to see.
And you can see 2 photos, 1 is can find the path, 1 is can not


Look like adding the border can make it’s easier to find the path, but as photo, it can not find the path

I would make sure the object origin point is in the center.

And to be safe make sure there’s no extra space in the image because the pathfinder uses the overall size (bounding box) and not the collision mask.

The left is better.

Also, make sure the target object isn’t inside the wall. You could alway use separate the target from the wall.

Make sure the obstacles aren’t rotated. The angle should be 0. The pathfinder doesn’t adjust for the angle.

Here is an extreme example. It added 100 pairs of objects. A player and a target. 96 found a path and 4 did not find a path.

The smaller object is the player and the larger is the target. The objects with a straight red line are the objects that failed. The red line is not the path. It is just a straight line to highlight which player is linked to which target.

The paths that failed all seem to have a target that is too close to a wall. Maybe, if the target was farther away from the wall.

The walls on the bottom are rotated copies of the walls on the top. You can see how the pathfinder ignored the walls and made a path through them.

The pathfinder isn’t perfect. Make sure the other tips are tried. Alwaya check if a path is found and if it’s not then try again.

For anyone curious of how I tested this. Here are the events. I used player and player2 for the target. The text object has a default value of 0 so I didn’t need a variable.

Edit: I was doing some more testing to try and figure out why some of my paths were failing.

It might sound confusing but as I said, the bottom 3 walls were rotated instead of resized. So, the pathfinder sees the walls as if they weren’t rotated.

The grey blocks represent where the walls would be if they weren’t rotated. While I was separating the target object from the wall, it wasn’t being separated from the position that the pathfinder uses. So, the pathfinder still thinks the path is blocked.

The main thing that this proves is that. Obstacles shouldn’t be rotated. The behavior uses the width and height of the obstacle. When rotated, the width and height doesn’t change. The behavior probably should use the bounding box.

1 Like

Wow, Thank you very much for so much effort.
It’s great way to test, I don’t even think about this method

I did not test your way for my scence, But I already do the same things as your recomment : I did not rotate the wall - just copy and resize, and I already make all point at the same center of the sprite, and also no extra border of colision
But it’s still same problem.
I’m very surprise that not much one notice or complain about this bug.
Look like it is more complicated than I though.

And strange things is look like the T shape of ostacle make pathfinding can not find the way some how
Like below photo, it can not find the path

PS: the screen is 1280x700, the pathfinder is just 12x12 px

I try but the complicated path, it can find, but T shape: can not. Strange…

Is the T shape 1 object? The pathfinder uses the bounding box not the collision or image. If you add a T then the pathfinder sees it as a rectangle. You would need to use separate objects.

Here’s what happens with a triangle. The collision mask matches the image but the pathfinder uses the overall size of the obstacle.

it’s the separate the object, I connect 2 objects just by moving only.
All the wall is the same. it’s just the individual rectangle. Cry,

1 Like

The below 2 cases: can not find the path
image
image

But If I move the target abit lower, it can find the path
image

What are the pathfinder grid settings?

These

It helps if you place the obstacles objects using a grid set to the width of the wall.

Say the wall is 16 pixels thick, the grid was 16x16 then the pathfinder would work best with a grid of 16x16 and an offset of 8 and 8.

That way the nodes that the pathfinder uses would be placed in the center of the obstacles and the center of the path. Everything just works smoother.

Thank you very much
I set the rid is small just 5px

Even I change it to 2 px, it’s same problem. gezzzz
I plan to make the obstacles is randomly by player, so I can not fix the position of the obstacles

Would you be willing to share your project? Upload the entire project folder including the assets folder to a file share site like Google drive or dropbox.

If the grid was small enough and the gap between the objects was large enough, there shouldn’t be an issue.

As for the user placing the obstacles. You could snap the objects to a grid.

Set position of object X to trunc(X/gridSize) * gridSize, Y to trunc(Y/gridSize) * gridSize

Thank you so much for keep helping me.
I’m very new bie and it’s not a project.
I have few ideas, and each idea I try to figure out how to build the game.

So many small scence with just test how it work and how possible it is.

Thank you very much for the way of place the obstacle
I will follow this way to test, not just randomly place which we have some kinds of bug.

Again, thank you very much

By the way, I want the user can place the different obstacles on the scene then path finding to find the path.
Do you know the topic about this issue?
I love to learn and know all the problem I can face with

I’m sorry, I found the way to move.
Thank you very much.

1 Like