View attachment 58996
Here's my shitty paint skills. xD
-x to +x
-y to +y
Think of the boxes like this when doing your checks.
Let's say we want to check for the pink box.
What do you need to check for?
We can clearly see that it's -x, and we can see that it is +y.
We can also see that 1 column is x, not -x or +x, just x.
Since x is negative and neutral for the pink box we use
<=
less then or equal to.
Think of current position as position (x = 0, y = 0, z = 0).
if target position is (x = -2, y = +2, z = 0) we can see that -2 is less then 0, and that 0 == 0, so we use less then or equal to.
<=
Can do the same for y. +2 is more then 0, and the box never touches the centre line, so it's only above. so we use greater than
>
So let's write the full equation.
Lua:
local cur_pos = blah
local tar_pos = blahblah
if tar_pos.x <= cur_pos.x and tar_pos.y > cur_pos.y then
Now when we check this area, since the south side of the black box touches the pink box, we just turn the character to face opposite. (north)
And then you do similar checks for the other 3 directions.
--
Of course this is just 1 way of doing these checks.
It's a simple and effective method.
Once you understand the basic concept, you can of course make the direction check more complex to account for the diagonals, et cetera, but it's quite a bit harder and will require more effort.
See what you can do on your own, and decide if it's worth the effort to do the more advanced way, or the simple way.