Fareyle hareket eden bir nesne arasındaki mesafeyi kontrol etmek için mesafe formülünü kullanmam gerekir. Ancak, totalDistance yalnızca 1'e geri dönmeye devam ediyor ve neden emin değilim.Java'da mesafe formülünü kullanma
float mouseX = Engine.getMouseX(); //gets X coordinate of the mouse
float mouseY = Engine.getMouseY(); //gets Y coordinate of the mouse
graphic.setDirection(mouseX,mouseY); //object faces mouse
float currentX = graphic.getX(); //gets X coordinate of object
float currentY = graphic.getY(); ////gets Y coordinate of object
double distanceX = (Math.pow((currentX - mouseX), 2)); //calculate (x2-x1)^2
double distanceY= (Math.pow((currentY - mouseY), 2)); //calculate (y2-y1)^2
double totalDistance = (Math.pow((distanceX+distanceY), (1/2)));
//calculate square root of distance 1 + distance 2
System.out.println("totalDistance = "+totalDistance); //prints distance
Tekrarlama olabilir [2 ints bölünme yerine başka bir int bir float üretmek nasıl yapılır?] (Http://stackoverflow.com/questions/787700/how-to-make-the-division- of-2-ints-üretmek-a-float yerine-başka-int) – resueman