Enemy AI Movement one axis at a time (8 directional - 2.5d) towards player/target

I’m having real trouble with this, i have a character which uses .GetAxisRaw to move in 8 directions in a 2.5D environment, see pic:

alt text

The issue is, i don’t think there is anyway i can use the same system(GetAxisRaw) for my Enemy AI movement?
I have tried various scripts for other methods and they all seem to move the Enemy AI between x,y causing the Enemy to take the shortest distance to the target which looks like he is Iceskating in a 2.5d Environment.

What i need is a way to Lock movement to one axis/direction(of the 8) at a time while moving towards the player/target.

Thanks!

You can take the position of the player as a Vector2 and subtract the position of your enemy, also as a Vector2.

You now have a direction vector towards the player.
You can then either do something involving angles (and possibly the cross product between the vectors as Vector3s to determine direction), or you can simply inspect the x and y coordinates of the direction vector and use that to determine which of the 8 direction to move in.

Then, once you have determined that, you then move the enemy in the appropriate direction.

I don’t exactly know how to program AI-movement, but if you use any commonly used pathfinding systme (i.e. Dijkstra’s Algorithm or A*), and a grid-based node-path, why don’t set your AI up to only move along one of 8 nodes?

If you have no clue what I am talking about, donot fear. I highly recommend watching this video-series by quill18creates: Civilization/Dungeon Tile Movement & Pathfinding
It is very good, and quill18 explain’s the system behind that very well.