I have a question. I'm playing around some 2D game dev, particularly AI and i've come onto a problem that I would love some help in solving. I know that there must be some simple solution to my problem and I'm over complicating it, I've looked but cant seem to find anything.
The problem is that I have a 2D world that wrapped around a 2D playing field, i.e. (when x > wide : x = 0 ...). I'm trying to do simple follow and flee type AI and I had the obvious problem that when one object is following another which goes off the edge of the screen and appears at the opposite side, it does not follow off the edge but has to turns around.
The only robust way that I could come up with is to calculate is as follows :
Assume that the pos can exists at 9 position (for each side of the screen) i.e
In the following X is following # (the real grid in in the middle one)