0
我使用下面的代碼在一個特定的時間段輪流我的遊戲對象:遊戲對象不旋轉糾正指定的角度
IEnumerator RotateMe(Vector3 byAngles, float inTime)
{
Quaternion fromAngle = transform.rotation ;
Quaternion toAngle = Quaternion.Euler(transform.eulerAngles + byAngles) ;
for(float t = 0f ; t < 1f ; t += Time.deltaTime/inTime)
{
transform.rotation = Quaternion.Lerp(fromAngle, toAngle, t) ;
yield return null ;
}
}
public void runCoroutine(Vector3 destination) {
StartCoroutine(RotateMe(destination, 0.5f));
}
然後我把它以下列方式:
runCoroutine(new Vector3(0,0,-90));
我從測試中意識到我的遊戲對象不是旋轉到指定的角度,而是關閉它們。不確定是什麼導致了這一點。
這是一個簡短的答案:'t <= 1' – Draco18s
@ Draco18s仍然有相同的問題。我試着將時間從0.5秒減少到0.1秒,而且更加不穩定。 – Hilarious404
嘗試添加'transform.rotation = Quaternion.Lerp(fromAngle,toAngle,1);'到方法的末尾。 – Draco18s