Im試圖旋轉我的玩家面對最後一次點擊的位置。我已經很好地執行此操作,但是現在我想要以設定的速度旋轉播放器,而不是立即改變旋轉的精靈。 我試過了幾種我在網上找到的方法,但沒有一種適合我。這是我的東西統一:使用Lerp/Slerp圍繞Z軸旋轉物體
void Update()
{
if (Input.GetMouseButtonDown (0))
{
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation= Quaternion.Euler(0f, 0f, rot_z - 90);
Instantiate(ProjectilePrefab, transform.position, transform.rotation);
}
}
上面的代碼工作正常,但它不顯示任何移動。我試圖做到這一點,但位置是錯誤的,旋轉也是瞬間的:
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
var newRotation = Quaternion.LookRotation(diff);
newRotation.y = 0.0f;
newRotation.x = 0.0f;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 30);
ANy ideas?