Skip to main content
4 of 4
added 135 characters in body

Euclidean distante = sqrt (dx * dx + dy * dy), for your distance you need to define dx as min(abs(x2-x1),screenwidth-abs(x2-x1)) same thing for dy.

Usualy the direction vector is Pt - Pm (Position vector target - Position vector missile). In your case you can define Direction vector x component as

if (x2-x1)>=0
  if (abs(x2-x1) < abs((x2-x1)-width))
    DirX = x2-x1;   
  else
    DirX = (x2-x1)-width;
else
  if (abs(x2-x1) < abs(width + (x2-x1))
    DirX=x2-x1;
  else
    DirX= width + (x2-x1);

enter image description here

In the same way (using HEIGTH) you can get DirY.