12/05/30 16:34:15.75
javaでシューティングゲームつくっていて
目標に向かって飛んでいくっていうメソッドをつくったんですけど
どうもうまくいきません。何がおかしいのかもよくわかりません。
目標Bに向かってAが進む
double speedX x座標の速さ
double speedY y座標の速さ
double unitSpeed ユニットの速さ
double theta aとbの角度
double targetX aとbのx座標の距離
double targetY aとbのy座標の距離
public void homing()
{
Point a = aの画像の中心;
Point b = bの画像の中心;
(targetX) = (double)(b.x - a.x);
(targetY) = (double)(b.y - a.y);
theta = Math.atan2(targetY,targetX);
speedX = Math.cos(theta) * unitSpeed;
speedY = Math.sin(theta) * unitSpeed;
}
わかりづらいかもしれませんが
アドバイスをいただけたら幸いです。