我使用此行通过鼠标旋转对象:
MutableLiveData
但是,我想像在Sketchfab中那样使用鼠标旋转对象时有些延迟,以使其平滑,只是不确定如何正确执行此操作。我对四元数不是很熟悉。
有人可以给我一些有关如何解决这个问题的建议吗?
答案 0 :(得分:0)
旋转它有点复杂。这是您想要的工作版本:
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使其接近。