diff options
Diffstat (limited to 'Assets')
| -rw-r--r-- | Assets/Prefabs/Camera.prefab | 3 | ||||
| -rw-r--r-- | Assets/Scripts/CameraHandler.cs | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/Assets/Prefabs/Camera.prefab b/Assets/Prefabs/Camera.prefab index 8a70e9c..29141d5 100644 --- a/Assets/Prefabs/Camera.prefab +++ b/Assets/Prefabs/Camera.prefab @@ -191,6 +191,9 @@ MonoBehaviour: minimumPivot: -35 maximumPivot: 35 cameraSphereRadius: 0.2 + ignoreLayers: + serializedVersion: 2 + m_Bits: 1024 cameraCollisionOffSet: 0.2 minimumCollisionOffSet: 0.2 --- !u!1 &7048044712634968914 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); |
