What would it take to get orthogonal (non-diagonal) movement?

I have a requirement that my NPCs can only move in cardinal directions (north, south, east, and west), no diagonal movement. What would it take to accomplish this using Astar?

Thank you.

Hi

Set “Neighbours” in the grid graph settings to “Four”.

I don’t see a “Neighbors” in the inspector. There’s a “Connections”, but setting that to four (from eight) didn’t seem to do much.

Seems I had a smoother on my Seeker. Removing that and setting “Connections” to four did make the path orthogonal (no diagonals), but the seeker is still cutting corners. I need it to only move in cardinal directions.

Also, movement along both axis now looks makes a zig-zagging diagonal line. Is it possible to get that to move along one direction, and then the next? So instead of a zig-zagging diagonal line, it’s more like an “L”?

Thank you for your help.

Hi

Ah, right, it is called “Connections”.
The included movement scripts will not follow the path exactly since in most games that just looks bad, if you want a movement script which follows the path exactly (no cutting corners) you will have to write your own.
You can try to experiment with the settings (like “pick next waypoint distance”) on the movement script you are using.

Try experimenting with the Heuristic settings in A* Inspector -> Settings. Changing it to Manhattan might give you the behaviour you are looking for.

Thank you. It should be able to write that movement script, and Manhattan looks pretty good.

One more question. I need to avoid collisions between NPC, but still maintain the cardinal movement. Right now when there’s a collision, they seem to rotate around each other to resolve it. Ideally I’d like them to avoid each others’ paths to begin with, though if that’s not realistic, can I get them to move out of the way without going diagonal?

Hi

Are they simultaneously moving through the graph?
If so, that is a very hard problem (called cooperative pathfinding) which I have not implemented in this project. If only one agent moves around at a time, it is possible to solve it however.

They are moving through the same time, yes. Do you have any suggestions for how to deal with that?

Well, it is a very hard problem to solve unfortunately. It is definitely not something this library can handle as it requires very specialised code.
At least to solve it optimally, maybe there is a simpler way to solve it in a “good enough” manner, but I can’t say I have read up on that a lot. Sorry.

You know the puzzle game where you are supposed to reorder small squares so that the numbers on the squares end up sorted, like the image below.

Imagine each square being a unit and ordering the unit to go to their final (sorted) positions. The algorithms for cooperative pathfinding would need to be able to solve that puzzle.
This is one case where it is easy to illustrate that cooperative pathfinding is hard.

Nothing to be sorry for.

Thank you for your response and your time.