Jelajahi Sumber

滚轮时根据鼠标位置微移

Void_F 4 bulan lalu
induk
melakukan
c4694a1f9d
1 mengubah file dengan 17 tambahan dan 0 penghapusan
  1. 17 0
      Assets/AIPagedLod/Scripts/WebGL/CameraBirdSec.cs

+ 17 - 0
Assets/AIPagedLod/Scripts/WebGL/CameraBirdSec.cs

@@ -116,6 +116,23 @@ public class CameraBirdSec : MonoBehaviour
             {
                 OnDistanceChange?.Invoke(Input.GetAxis("Mouse ScrollWheel"));
             }
+            Debug.Log($"{Input.mousePosition} {Screen.width*0.5f}:{Screen.height*0.5f}");
+            float offSetX =  Screen.width * 0.5f-Input.mousePosition.x;
+            float offSetY =   Screen.height * 0.5f-Input.mousePosition.y;
+            Vector3 moveDirection = Vector3.down * offSetY*translateSpeed + Vector3.left * offSetX*translateSpeed;
+            // 平滑移动摄像头到目标位置
+            target.position += moveDirection;
+            //限制移动范围
+            if (fixMoveRange)
+            {
+                Vector3 finalPos=target.localPosition;
+                finalPos.x = Mathf.Clamp(finalPos.x, min_X, max_X);
+                finalPos.y = Mathf.Clamp(finalPos.y, min_Y, max_Y);
+                target.localPosition = finalPos;
+            }
+            Vector3 targetPosition = target.position + Quaternion.Euler(new Vector3(rotateXAngle, 0, 0)) * offset.normalized * currentDistance;
+            // 摄像头平滑移动到目标位置
+            transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smoothSpeed * 2);
         }
       
         // 鼠标左键拖拽平移摄像头