2
问题libgdx box2d body - 为什么身体在到达接触点位置后发抖?
如果子弹到达目的地的身体颤抖,背部和堡垒从目的地到以前的位置,然后再次回到 目的地等..等等堡... 奇怪的行为
示例代码
Vector2 targetPosition =
// Copied target position and subtracted by bullet position
Vector2 targetDirection = targetPosition.cpy().sub(bulletPosition);
float distance = bulletPosition.dst(targetPosition);
float speed = 16;
Vector2 velocity = targetDirection
.cpy() // Copied target direction
.nor() // normalize to avoid getting the direction as speed
.scl(speed); // scaled by speed
// the distance is not accurate, so we get the time step as defined precision
float DEFINED_PRECISION = Constants.TIME_STEP;
// check if the bullet is near or maybe match the touch point
if(distance >= DEFINED_PRECISION) {
// move the bullet
body.setLinearVelocity(velocity);
} else {
// stop the bullet
body.setLinearVelocity(0,0);
}