【问题标题】:Smooth with mouse object rotation平滑鼠标对象旋转
【发布时间】:2019-09-25 21:07:38
【问题描述】:

我用这条线用鼠标旋转对象:

this._obj.transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0), Time.unscaledDeltaTime * this.speed);

但是我想解决这个问题,在 Sketchfab 中使用鼠标旋转对象时会有一些延迟,只是不确定如何正确执行此操作。我对四元数不是很熟悉。

有人可以给我一些关于我如何处理这个问题的建议吗?

【问题讨论】:

  • 您需要通过鼠标 X 轴缩放幅度并保持轴不变。试试this._obj.transform.Rotate(Vector3.down, Time.unscaledDeltaTime * this.speed * Input.GetAxis("Mouse X"));

标签: c# unity3d rotation smoothing


【解决方案1】:

只是旋转它有点复杂。这是您想要的工作版本:

    public Vector3 hiddenRotation;

void Start()
{
    hiddenRotation = this.transform.rotation.eulerAngles;
}

void Update()
{
    float sensitivity = 5.0f;
    //Get rotation vector
    Vector3 rot = new Vector3(0, -Input.GetAxis("Mouse X"), 0) * sensitivity;
    //Add rotation to hidden internal rotation
    hiddenRotation += rot;

    //Specify speed at which the cube rotates.
    float speed = 50.0f;
    float step = speed * Time.deltaTime;

    //Set new rotation (changing this function may allow for smoother motion, like lower step as it approaches the new rotation
    this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(hiddenRotation), step);

}

它使用隐藏的旋转并让 transform.rotation 接近它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 2016-08-25
    相关资源
    最近更新 更多