统一轮换

时间:2014-07-01 15:37:39

标签: rotation unity3d quaternions

我正在尝试使用lerp命令旋转游戏对象,但是我收到以下错误:

  

错误CS0029:无法隐式转换类型float' to UnityEngine.Quaternion'

这是我正在使用的代码

box.rotation = Quaternion.AngleAxis(NewAngle, Vector3.right);
boxAngle = box.rotation.x;
targetAngle = 90.0f;
NewAngle = Mathf.Lerp(boxAngle, targetAngle, smooth * Time.deltaTime);

有人能指出我正确的方向吗?我做错了什么?

2 个答案:

答案 0 :(得分:4)

假设boxTransform,这应该可行,但如果您只在一个轴上旋转,则使用起来会更容易

box.eulerAngles=new Vector3(NewAngle, 0f, 0f);

此外,还有其他两个潜在问题:

  1. 在它设置之后进行练习 - 你有一个潜在的一帧延迟
  2. gimbal lock或modulo 360问题(想想如何将350 lerp to 90 - 它将会走得很远)
  3. 怎么样:

    Quaternion targetAngle=Quaternion.Euler(90f, 0f, 0f);
    box.rotation=Quaternion.Lerp(box.rotation, targetAngle, Time.deltaTime*smooth);
    

答案 1 :(得分:0)

当将box声明为变换变量时,

脚本正在为我工​​作而没有任何错误。