From 88d8fefa0a328435103fafa8ee59f3aa3c11492d Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Tue, 19 Nov 2024 17:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A7=86=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/Character/CameraControl.cs | 10 +++--- .../Character/PlayerMovement_Jpystick.cs | 32 ++++++++++++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/xiaofang/Assets/Script/Character/CameraControl.cs b/xiaofang/Assets/Script/Character/CameraControl.cs index 02d263e6..532963be 100644 --- a/xiaofang/Assets/Script/Character/CameraControl.cs +++ b/xiaofang/Assets/Script/Character/CameraControl.cs @@ -65,11 +65,11 @@ public class CameraControl : MonoBehaviour // 鼠标控制: - if (Input.GetMouseButton(0)) - { - angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed; - angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed; - } + //if (Input.GetMouseButton(0)) + //{ + // angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed; + // angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed; + //} // 设置垂直移动的限制。 diff --git a/xiaofang/Assets/Script/Character/PlayerMovement_Jpystick.cs b/xiaofang/Assets/Script/Character/PlayerMovement_Jpystick.cs index 1f2de9ef..f7c3b65d 100644 --- a/xiaofang/Assets/Script/Character/PlayerMovement_Jpystick.cs +++ b/xiaofang/Assets/Script/Character/PlayerMovement_Jpystick.cs @@ -138,14 +138,36 @@ public class PlayerMovement_Jpystick : MonoBehaviour } + //void HandleViewSwipe(Touch touch) + //{ + // // 滑动视角逻辑 + // float horizontalSwipe = touch.deltaPosition.x * 0.1f; // 可调整灵敏度 + // float verticalSwipe = -touch.deltaPosition.y * 0.1f; + + // cameraTransform.Rotate(0, horizontalSwipe, 0, Space.World); + // cameraTransform.Rotate(verticalSwipe, 0, 0, Space.Self); + //} void HandleViewSwipe(Touch touch) { - // 滑动视角逻辑 - float horizontalSwipe = touch.deltaPosition.x * 0.1f; // 可调整灵敏度 - float verticalSwipe = -touch.deltaPosition.y * 0.1f; + // 检查触摸状态 + if (touch.phase == TouchPhase.Moved) + { + float sensitivity = 0.1f; // 调整灵敏度 + float horizontalSwipe = touch.deltaPosition.x * sensitivity; + float verticalSwipe = -touch.deltaPosition.y * sensitivity; - cameraTransform.Rotate(0, horizontalSwipe, 0, Space.World); - cameraTransform.Rotate(verticalSwipe, 0, 0, Space.Self); + // 当前旋转角度 + Vector3 currentRotation = cameraTransform.eulerAngles; + + // 垂直角度限制 (-80 到 80) + float newVerticalAngle = Mathf.Clamp(currentRotation.x + verticalSwipe, -80f, 80f); + + // 计算目标旋转 + Vector3 targetRotation = new Vector3(newVerticalAngle, currentRotation.y + horizontalSwipe, 0); + + // 平滑过渡旋转 + cameraTransform.eulerAngles = Vector3.Lerp(cameraTransform.eulerAngles, targetRotation, Time.deltaTime * 5f); + } } public void MoveState()