1
下面是以下鏈接,我如何使用觸摸點將子彈移動到目標位置。 (Move a body to the touched position using libgdx and box2d)libgdx - Box2d機體如何檢查子彈位置是否已達到目標位置?
我的問題是,如果子彈體已達到目標位置,我該如何停止子彈體。
我已經嘗試了下面的代碼,它的工作正常。
PIXEL_TO_METER = 1/32.0f
time step = 1/45.0f, velocity iteration = 6, position iteration = 2
float distanceTravelled = targetDirection.dst(bulletPosition);
if(distanceTravelled >= MAX_DISTANCE){
// stop
} else {
// move body
}
但我想停止在目標位置上的子彈,也不在MAX_DISTANCE上。但我不知道該怎麼做。
您好感謝,所以如果我使用1/45.0f時間步長。 defined_precision值是多少? – ronscript
也添加了問題,在你的例子中你使用的是targetPosition而不是targetDistnce。糾正我,如果我的錯誤是targetPosition已經正常化? – ronscript
目標位置是目標的位置(矢量),而不是子彈將要前進的方向 - 正確化位置的原因是什麼? –