Unity 物体围绕自身中心旋转而非轴心_Unity3d

============================================================

Unity 物体围绕自身中心旋转而非轴心_RotateAround_02

在上面两张图坐标中心都在轴中心,但是如果用Rotate进行旋转,第一张是正确的,第二张进行了缩放的物体旋转并不会围绕自身中心旋转.

解决的方法:

//相对于某一个点旋转
//point 相对于哪个点旋转
//axis  相对于point的 哪一个轴旋转
//angle 旋转的角度 和 旋转的速度
transform.RotateAround(Vector3 point, Vector3 axis, float angle);

示例:

if (Event.current.button == 1)//拖拽旋转
{
    var mouseX = Input.GetAxis("Mouse X");
    var mouseY = Input.GetAxis("Mouse Y");
    if (Mathf.Abs(mouseX) > Mathf.Abs(mouseY))
       areaParent.RotateAround(dragMoveBoxCollider.bounds.center, Vector3.up, mouseX * dragRotateSpeed * Time.deltaTime);
    else
       areaParent.RotateAround(dragMoveBoxCollider.bounds.center, Vector3.up, mouseY * dragRotateSpeed * Time.deltaTime);
 }