One problem about moving to a target using only 4 directions is that there are multiple vectors that lead to the same result.
It may always be in two phases: one going horizontally, then vertically, but the other way around also works. If your AI is as far as the target in both X and Y, which direction should it take first? (1,0) or (0,1)?
Now, if you just want a vector to a point but that uses only horizontal or vertical directions, you can isolate the problem into a function, like this:
static func get_direction(from, to):
var diff = to - from
if abs(diff.x) > abs(diff.y):
return Vector2(sign(diff.x), 0)
return Vector2(0, sign(diff.y))
But again, you need to think about the effect of this across time, because applying the same approach as a "float" direction will make your AI oscillate weirdly as soon as it reaches the point where X and Y distances are equal.