【发布时间】:2017-11-26 04:35:09
【问题描述】:
我正在使用以下代码在给定时间段内旋转我的游戏对象:
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 仍然有同样的问题。我尝试将时间从 0.5 减少到 0.1,结果更加不稳定。
-
尝试在方法末尾添加
transform.rotation = Quaternion.Lerp(fromAngle, toAngle, 1);。