【发布时间】:2020-08-06 02:15:37
【问题描述】:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if( selectedObjs.Count==0&&Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray,out hit,100, 1 << 9))
{
currentPos = hit.point;
}
}
if (mouseClickMode !=3 && mouseClickMode != 4 && !uiMenu_on
&& Input.GetMouseButton(0))
{
float rotX = Input.GetAxis("Mouse X");
float rotY = -Input.GetAxis("Mouse Y");
if (selectedObjs.Count > 0)
currentPos = objectManager.ReturnPos(selectedObjs[0]);
transform.RotateAround(currentPos, Vector3.up, Time.deltaTime *450* rotX);
transform.RotateAround(currentPos, Vector3.right, Time.deltaTime*450 * rotY);
}
这种旋转先在 x 轴上旋转,然后在 y 轴上旋转。
但是当鼠标沿对角线移动时,轴就不是对角线了。当鼠标沿对角线移动时,如何让对象围绕对角轴上的点旋转?
【问题讨论】:
-
请不要在
Update中使用Camera.main- 您应该不经常使用它,或者最好在Start或Awake中使用它并缓存结果。 See here for more information -
我现在正在使用一种方法,如果没有用相机点击对象,则围绕用鼠标拍摄的位置旋转相机,但该方法并不完全正确。