Skip to main content
2 of 4
added 426 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
  DirX= min(x2-x1 , width -(x2-x1))
else
  DirX= max(x2-x1 , width + (x2-x1))

enter image description here

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