我試圖通過在360°(右邊或左邊取決於點更靠近哪邊)上儘可能小的路線來旋轉一個精靈,讓我們說它是一支槍,並且我是有幾個問題。如何將一個精靈旋轉到一個點?
在一個圓上,它從359°跳到0°,所以我不能直接使用我的目標角度 - 當前角度。
請記住,我正在使用SFML,因此它在isRotating爲true時正在執行每個函數的功能。
這是一種提供給我的資料:
//The angle in degrees of my sprite
float currentAngle = pSprite.getRotation();
//The angle is needs to be once the rotation is over
float targetAngle = float(atan2(deltaY,deltaX) * 180/(atan(1)*4) + 180);
我使用的速度變量來遞增或遞減每幀的角度的值。
distance = Speed*Time.asSeconds();
currentAngle += distance;