diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-31 14:05:03 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-31 14:05:03 +0800 |
| commit | e8e1a9db5babfeb71561e87e089173aaa1c29438 (patch) | |
| tree | 349025c289ae59db542a51838ccf0177405c03f5 /Assets/Scripts | |
| parent | c21c62c0b6554691afd239419e7497f0c6d61518 (diff) | |
修复后退相机bug
Diffstat (limited to 'Assets/Scripts')
| -rw-r--r-- | Assets/Scripts/CameraHandler.cs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Assets/Scripts/CameraHandler.cs b/Assets/Scripts/CameraHandler.cs index b995d93..a1cd569 100644 --- a/Assets/Scripts/CameraHandler.cs +++ b/Assets/Scripts/CameraHandler.cs @@ -18,7 +18,6 @@ namespace DS // ========== 私有引用与状态 ========== private Transform _myTransform; // 当前对象的 Transform 缓存 private Vector3 _cameraTransformPosition; // 用于 Lerp 的摄像机局部位置 - private LayerMask _ignoreLayers; // 忽略的碰撞层(玩家、UI 等) private Vector3 cameraFollowVelocity = Vector3.zero; // SmoothDamp 速度参考值 private bool _cursorLocked = false; // 鼠标是否锁定 @@ -45,6 +44,7 @@ namespace DS // ========== 碰撞检测参数 ========== [Header("Collision Settings")] public float cameraSphereRadius = 0.2f; // 球体投射的半径 + public LayerMask ignoreLayers; // 忽略的碰撞层(玩家、UI 等) public float cameraCollisionOffSet = 0.2f; // 碰撞后摄像机偏移量 public float minimumCollisionOffSet = 0.2f; // 最小偏移量,防止穿透 @@ -56,8 +56,6 @@ namespace DS singleton = this; // 设置单例 _myTransform = transform; // 缓存自身 Transform _defaultPosition = cameraTransform.localPosition.z; // 记录默认 Z 距离 - // 忽略层级:8(玩家)、9、10;使用位取反运算 - _ignoreLayers = ~(1 << 8 | 1 << 9 | 1 << 10); // 自动绑定 PlayerLocomotion if (player == null) @@ -164,7 +162,8 @@ namespace DS cameraSphereRadius, direction, out hit, - Mathf.Abs(_targetPosition))) + Mathf.Abs(_targetPosition), + ignoreLayers)) { // 计算枢轴到碰撞点的实际距离 float dis = Vector3.Distance(cameraPivotTransform.position, hit.point); |
