使用鼠标对象旋转平滑
Smooth with mouse object rotation
我用这条线用鼠标旋转对象:
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 接近它。
我用这条线用鼠标旋转对象:
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 接近它。