I withdraw my previous statement "which doesn't work", and replace it with the more accurate version "which solves a problem which likely is different from what the OP was talking about".
I didn't write the long version, because it didn't explain the humour I saw in it.
Let's forget about that and get back on-topic...
XiotexStudios, if you're still looking for a solution, then this might help:
halfworld = worldsize / 2; targetX = player.x; if (targetX < (agent.x - halfworld)) targetX += worldsize;if (targetX > (agent.x + halfworld)) targetX -= worldsize;targetX -= agent.x;targetY = player.y - agent.y; Move_In_Direction(Get_Direction_To(targetX, targetY));
The 2 if-statements, plus the following 2 lines, is what converts the players coordinate to agent-space. The Get_Dir_To()-function calculates a direction from coordinate 0:0 towards the supplied parameter.
You are probably already using such a function, and only need to modify it to assume that the from-coordinate is always at 0:0.
Good luck!