How can I remove diagonal movement?

Hi. Is there any way of removing diagonal movements? I am working on a 2D top down game and I want my enemies to just walk in 4 directions. Up, down, right and left. Thanks in advance. :grinning:

I believe setting the number of connections to 4 will solve this. See below:
image **

1 Like

@cynn thank you for your fast reply :grinning:. That looks a little better. However, the enemy still goes diagonally in some situations.

Is cutCorners on? Im not sure what that does, but it sounds like it might do that :stuck_out_tongue:

@cynn Unfortunately, no. It has no effect on the enemy ai. Funny :joy:
Or do I have to add some kind of penalty in the script so that the enemy no longer goes diagonally. If so, how should I do this and where?

Hi

If you want the agent to always be forced to move up, down, right and left without any deviation then you might want to use the AILerp script instead of the AIPath movement script.

The AIPath script will always try to move smoothly while the AILerp script will move along the path without any additional smoothing.

See https://arongranberg.com/astar/docs/movementscripts.html
and https://arongranberg.com/astar/docs/ailerp.html

@aron_granberg thank you very much. This is working fine. :grinning:

1 Like