我想根據玩家手臂的旋轉來拍攝一個物體(咒語)。這個咒語應該是從手中出來並射向鼠標所在的地方(手臂旋轉並指向鼠標的位置)。這是手臂在遊戲中旋轉的方式。在libgdx中基於手臂旋轉的拍攝對象java
public boolean mouseMoved(int screenX, int screenY) {
tmp.x = screenX;
tmp.y = screenY;
tmp.z = 0;
cam.unproject(tmp);
rot = MathUtils.radiansToDegrees * MathUtils.atan2((float)tmp.y - (float)player.getArmSprite().getY() - player.getArmSprite().getHeight(),
tmp.x -player.getArmSprite().getX() - player.getArmSprite().getWidth());
if (rot < 0) rot += 360;
//Last right or left means if hes looking left or right
if(player.lastRight)
player.setObjectRotation(rot + 80);
if(player.lastLeft)
player.setObjectRotation(-rot - 80);
這是法術應該如何拍基於脫旋轉
//destination is a vector of where on screen the mouse was clicked
if(position.y < destination.y){
position.y += vel.y * Gdx.graphics.getDeltaTime();
}
if(position.x < destination.x){
position.x += vel.x * Gdx.graphics.getDeltaTime();
}
然而,這是非常靠不住的,從來沒有真正反應也應該有一些例外的方式。它從手中發射,然後如果y軸相等,它完全平均並且一直到它到達x位置,我希望它從手中發射到從點a到點b完全直線的位置,這很清楚一個旋轉問題,我似乎無法弄清楚如何解決。
這裏是發生了什麼事
的圖像的紅色顯示我點擊,你可以看到它首先到達X位置,現在正行駛到Y,當它應該已經達到我首先點擊的x和y位置
對此問題的任何幫助都非常感謝!
目前還不清楚你有什麼問題。 「won and,從不真實地反應它應該怎樣」是什麼意思?請更具體一些,比如「它只是中途移動」或「手臂繞着一圈旋轉並將屏幕彈出到用戶的鼻子中」 –
@RyanBemrose我編輯它 – Temo