在Box2D中拍摄(LibGDX)
我应该设置哪些值:“setLinearVelocity(x,y);”对于物体,如果我想从玩家身体的中心拍摄到鼠标的位置在Box2D中拍摄(LibGDX),libgdx,box2d,bullet,Libgdx,Box2d,Bullet,我应该设置哪些值:“setLinearVelocity(x,y);”对于物体,如果我想从玩家身体的中心拍摄到鼠标的位置 我有这些可用变量:mouseX、mouseY、playerX、playerY。否决票可能是因为这个问题以前已经回答过,您应该在打开新问题之前先进行搜索 float velx = mouseX - playerX; float vely = mouseY - playerY; float length = Math.sqrt(velx * velx + vely * vely);
我有这些可用变量:mouseX、mouseY、playerX、playerY。否决票可能是因为这个问题以前已经回答过,您应该在打开新问题之前先进行搜索
float velx = mouseX - playerX;
float vely = mouseY - playerY;
float length = Math.sqrt(velx * velx + vely * vely);
if (length != 0) {
velx = velx / length;
vely = vely / length;
}
float finalVelx = velx * speed;
float finalVely = vely * speed;
setLinearVelocity(finalVelx,finalVely);