Separating objects with pathfinding

I’m using a method of movement where the player pathfinds but only a given amount in the direction indicated by a pushable button. For instance, 16 left. How about I call it incrimental pathfinding? Problem is, if I use obstacle for pathfinding on barriers, the pathfinding is messed up, probably due to the small size of the room, which is a red rectangle of barriers. However, if I just separate the objects, the player teleports past the barriers. How can i fix this?


The grid based linked object behavior might be a better fit depending on your needs. It’s a lot more involved but it has distance based movement.

The snap function and other behaviors don’t work well with the pathfinder. They both want to move the object so they push back and forth.

The pathfinder uses a grid. You can see in this picture that the grid was aligned with the objects. So, everything just fits perfectly. It can detect the obstacles and it can place the object in the center of the path. You shouldn’t need the snap behavior or the separate. They don’t work well with the pathfinder behavior anyways.

The dots represent the points on the grid that the path finder uses to calculate a valid path. The object needs to be able to reach the point and fit completely within the grid cell. The object is also moved on this grid from point to point in segments using nodes. The lines show the path from node to node.

The pathfinder works best when the behavior grid lines up with the way the objects are place. If the scene is based on a 32x32 px grid then the pathfinder works best with the same size. It also helps to have the moving object’s origin in the center of the object. To align the objects in the center, it helps to put the grid offset to half the height and half the width.

That should allow the objects to get closer to the obstacles. Now, because you’re working in a 3D like environment, obstacles above the player cause a problem because the head collides with the wall but it should be the feet. The bottom of the object.

The easiest way around this is to use a smaller object for the pathfinder. Use an object slightly smaller than the grid and then use the sticker behavior to stick the player sprite to the pathfinder object. Make sure the mover objects origin is in the center of the object.

You can also use ray casts to detect obstacles as well as point is inside. This will help you know if and how far an object can move.

I’ll try to help you if you have further questions.

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

I reply to a lot of pathfinding questions. Some of those posts might help. I like to add examples. Sometimes with a link to a project.

https://forum.gdevelop.io/search?context=topic&context_id=60468&q=%40Keith_1357%20pathfinder%20order%3Alatest&skip_context=true