C# 平滑鼠标对象旋转

C# 平滑鼠标对象旋转,c#,unity3d,rotation,smoothing,C#,Unity3d,Rotation,Smoothing,我使用这条线使用鼠标旋转对象: this._obj.transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0), Time.unscaledDeltaTime * this.speed); 但我想让这一切变得更顺利,比如在Sketchfab中,当你使用鼠标旋转对象时,会有一些延迟,只是不知道如何正确地进行。我对四元数不太熟悉 有没有人能给我一些建议,告诉我如何处理这个问题?旋转它有点复杂。以下是您想要的工作版本: publ

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

this._obj.transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0), Time.unscaledDeltaTime * this.speed);
但我想让这一切变得更顺利,比如在Sketchfab中,当你使用鼠标旋转对象时,会有一些延迟,只是不知道如何正确地进行。我对四元数不太熟悉


有没有人能给我一些建议,告诉我如何处理这个问题?

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

    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来接近它。

您需要通过鼠标X轴缩放Magnitiue并保持轴恒定。尝试
this.\u obj.transform.Rotate(Vector3.down,Time.unscaledDeltaTime*this.speed*Input.GetAxis(“鼠标X”)非常感谢!工作起来很有魅力!