【问题标题】:Rotation in unity统一旋转
【发布时间】:2014-07-01 15:37:39
【问题描述】:

我正在尝试使用 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);

谁能指出我正确的方向?我做错了什么?

【问题讨论】:

  • 四分之一不是旋转。使用向量3

标签: rotation unity3d quaternions


【解决方案1】:

假设boxTransform,这应该可以工作,但如果你只在一个轴上旋转它会更容易使用

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

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

  1. 设置后出现延迟 - 您可能会出现一帧延迟
  2. gimbal lock 或模 360 的问题(想想 350 到 90 的 lerp 会如何 - 它会走很长的路)

怎么样:

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

【讨论】:

    猜你喜欢
    • 2021-05-24
    • 1970-01-01
    • 2021-05-29
    • 2015-08-12
    • 1970-01-01
    • 2015-07-07
    • 2019-04-14
    • 2021-12-07
    • 2017-08-18
    相关资源
    最近更新 更多