私のマウスと動くオブジェクトとの距離を調べるには距離式を使用する必要があります。しかし、私のtotalDistanceは1に戻り続けています。理由はわかりません。あなたはすべてのあなたの指数の計算にdouble
精度を指定する必要がありますJavaの距離式を使用する
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
の可能性のある重複した[2つのint型の除算を作成する方法ではなく、別のint型のフロートを作ります?](http://stackoverflow.com/questions/787700/how-to-make-the-division- of-2-ints-produce-a-float-another-int-int) – resueman