Make pathfinding collision less choppy

How do I…

Make the character NOT go through collision objects, but do it smoothly

What is the expected result

Explain what should happen when you run the game.

What is the actual result

Character either ignores collision sometimes (without the move way from collision command) or goes around collisions but in a very snappy and choppy way (with the move away from collision command)

Related screenshots AND videos

https://youtu.be/ZWkG-SqQkwE - Ignores collisions
https://youtu.be/J1-VE_-uifQ - Choppy, but acknowledges collisions

If you’re using pathfinding then you can’t use the separate objects. The separate objects pushes in 1 direction while the Pathfinder behavior wants to stay on its path. It looks like it’s teleporting because the separate objects is holding the object in place while the Pathfinder continues to try to move. Once the path takes the object to a place that it doesn’t collide with the walls, the separate objects stops pushing away so, it jumps to the other side of the wall.

Make sure when you make the walls, that you don’t make a copy of a wall and rotate it. The behavior doesn’t always work with rotated objects. It calculates the path sort of like the object isn’t rotated. So, it might go through objects. Just don’t rotate the objects.

Create an instance of the wall that’s taller and one that’s wider and then make copies of them. Meaning say 100 x 20 and 20 x 100 instead of rotating the first object. You can use the same object just don’t rotate it.

There is a nav mesh Pathfinder. IDK if that has the same issue. I usually use the default behavior. I just make sure I don’t rotate my objects.

Well the problem is, neither the agent (who is pathfinding) nor the walls (who are pathfinding objects) are ever rotated.

1 Like

Just for clarity. I meant rotated in the scene editor. Are all of the object angles set to 0?

Yes, yes they are. Everything is set to 0 degrees.

Are the obstacles set as impassable?

It can be tough to pathfind a tight area. You can use the Draw Pathfinding behavior to draw the path. Add the behavior, a shape painter and then add the action.

image

My events. I had to use a small player.

I set the patyhfinder grid size to 5 and 5 but it could be a little larger because I made the player smaller. It’s tough to get an object to hug the walls of a maze because the pathfinder isn’t as flexiable as it could be. It also helps to use an origin point set to the center of the object.

1 Like

I added events to draw the grid that the pathfinder uses. It helps to align the objects with the grid. I also unchecked the option to move diagonally.

Edit: the 2nd repeat should be camera height not camera width.

Edit: I’ll fix my events tomorrow. It’s late. I think it should be height for the 1st repeat and width for the second. I wish GD had a For… Next.

(edit: the hide tester object action is not needed)

It followed it much better.

My scene grid is 32 x 32.

My pathfinding settings.

With an pathfinder grid offest of 8 x 8 pixels. You can’t even move the player because there isn’t a valid position. The dots are all too close to the wall. The object needs to be able to fit completely in the target x,y.

image
.

This would probably be the best setup for objects aligned to a 32 x 32 grid. The grid points align perfectly to the open space and the obstacles.

1 Like

Hi Keith, I tried your events to draw the grid. It drew one diagonal line of dots from 0,0 to a bit more than halfway across the screen at the bottom. It looks like your screenshot doesn’t show all the events. If so, can you please post all of them? Thank you. Here is what I did.


Also, I have a Keith request, would you consider making the Show pathfinding grid events into an extension? It would be very handy for people to optimise their grid settings.
1 Like

The last event needs to be moved one indentation to the left. It should be equal with the 2nd repeat not a subevents.

This might be a nice addition to the existing draw Pathfinder extension. It would pair up nicely.

2 Likes

For anyone in the future who uses Keith’s show grid dots events, if your game resolution is portrait, changing CameraWidth() to CameraHeight() in both places worked for me.

2 Likes

I see it now, I copied and pasted the reapeat events. It should be width and width and height and height. If I remember it tomorrow, I’ll fix the image.

I actually tried to make a draw pathfinding grid extension a few weeks ago, but drawing lines instead of circles. I ran into some difficulties and went back to my project. So yes, I did wonder about the width height mis-match.

But I think it’s not just that, when I did mine back then, it was camerawidth/cellwidth that determined the y variable, not the x variable. They have to cross over, width does y and height does x. Or that was my experience anyway.

This is how I used your events and it worked for both portrait and landscape.


1 Like

Yes. That looks right. It cycles through X first and then Y. So the outer is Y and height while the inner is width and X. I somewget confused with nested loops. Things appear inverted when nested.

I don’t think that’s what’s happening? Using lines instead of circles as an example, I need to know what the screenwidth / cellwidth is to know how many lines to draw in the y direction where the top of the line is at y=0 and the bottom of the line is at screen bottom?





Update
Yes, sorry Keith, I hadn’t seen your edits when I wrote this and my previous post where in fact you had already mentioned swapping the repeats to have height as the outer.

I just meant that it’s y and then x but it does the inner repeat first or 1 row at a time. It’s all perspective.

But yes. Y uses height while X uses width.

1 Like

Soo my issue is fixed. If anyone needs it, i set the origin to the centre of the agent, and i set my virtual grid as 16 x 16 (because that is my pixel size), and the offset to half of that (8 x 8). Also i disabled diagonals. Now it works splendid. This is my code

1 Like

I’m glad it’s working. I was a bit surprised myself how perfectly it moves in a maze. It makes sense but I’m still surprised a bit.