想做一个展示台
参考: https://gamedev.stackexchange.com/questions/61381/rotate-an-object-smoothly-on-the-y-axis-in-unity
四元数是可以相乘的
if (Input.GetMouseButton(0))
{
var d = (target.position - m_MainCameraTrans.position).magnitude;
//transform.DOKill();
m_X -= Input.GetAxis("Mouse X") * 8 * d;
m_Y += Input.GetAxis("Mouse Y") * 4 * d;
}
Quaternion newRotation = Quaternion.AngleAxis(m_X, Vector3.up);
newRotation = Quaternion.AngleAxis(m_Y, m_MainCameraTrans.right) * newRotation;
//transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * Speed * 10);
if (newRotation != transform.rotation)
{
transform.DORotateQuaternion(newRotation, 0.4f);
}
if (Input.GetMouseButton(2))
{
var d = (target.position - m_MainCameraTrans.position).magnitude;
var x = Input.GetAxis("Mouse X") * 0.02f * d;
var y = Input.GetAxis("Mouse Y") * 0.02f * d;
transform.position += m_MainCameraTrans.up * y;
transform.position += m_MainCameraTrans.right * x;
}
CameraController.cs
var d = (target.position - transform.position).magnitude;
z -= Input.GetAxis("Mouse ScrollWheel") * d;
// far near limit
z = Mathf.Clamp(z, distanceMin, distanceMax);
Vector3 position = m_TargetOriginPos + -transform.forward * z;
// transform.position = position;
// smoothing
if (Vector3.Distance(position, transform.position) > 0.01f)
{
transform.DOMove(position, 0.4f);
}