我想以恒定速度在Y方向上旋转物体 . 当我停止时,我想以相同的方向旋转回Quaternion.identity .
public bool spin;
public float speed;
private void Update() {
if (spin) {
transform.Rotate (-Vector3.up, Time.deltaTime * speed, Space.World);
} else if (transform.rotaion != Quaternion.identity) {
transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.identity, Time.deltaTime * speed);
}
}
这很好用,但它会向相反的方向旋转 . 你如何强迫它继续向原始方向旋转到Quaternion.identity?
1 回答
RotateTowards
将采用最短路径到达目标 - 无论哪个方向 .旋转180度(或中途)时反转方向: