From 026b1d954ca4d568d128c13781890fd68ff4657f Mon Sep 17 00:00:00 2001 From: kerboul Date: Fri, 15 May 2026 14:44:35 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20cam=C3=A9ra=20=E2=80=94=20delta=20souris?= =?UTF-8?q?=20direct,=20toggle=20clic=20droit,=20no=20InputAxisController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Lit Mouse.current.delta directement (pas d'accrochage au bord d'écran) - CinemachineInputAxisController désactivé (on gère tout nous-mêmes) - OnEnable/OnDisable : lock/unlock automatique selon état Player - Clic droit = toggle cursor lock (pas besoin de maintenir) Co-Authored-By: Claude Sonnet 4.6 --- game/Assets/Scripts/CameraOrbitKeyboard.cs | 84 +++++++++++++++------- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/game/Assets/Scripts/CameraOrbitKeyboard.cs b/game/Assets/Scripts/CameraOrbitKeyboard.cs index a805034..5a3dfcd 100644 --- a/game/Assets/Scripts/CameraOrbitKeyboard.cs +++ b/game/Assets/Scripts/CameraOrbitKeyboard.cs @@ -3,53 +3,85 @@ using UnityEngine.InputSystem; using Unity.Cinemachine; /// -/// Adds ZQSD (AZERTY) / WASD (QWERTY) keyboard orbit for the Cinemachine camera. -/// Works in parallel with mouse orbit via CinemachineInputAxisController. -/// Attach to the CinemachineCamera GameObject alongside CinemachineOrbitalFollow. +/// Orbit camera via mouse delta direct (bypass CinemachineInputAxisController) +/// + keyboard fallback. Right-click toggles cursor lock. +/// Active uniquement quand le Player est actif (gameplay). /// public class CameraOrbitKeyboard : MonoBehaviour { - [Header("Orbit Speed (degrees/sec)")] + [Header("Keyboard Orbit Speed (deg/s)")] public float horizontalSpeed = 150f; - public float verticalSpeed = 80f; + public float verticalSpeed = 80f; - private CinemachineOrbitalFollow _orbital; + [Header("Mouse Sensitivity (deg/px)")] + public float mouseSensitivity = 0.2f; + + private CinemachineOrbitalFollow _orbital; private CinemachineInputAxisController _axisController; - void Start() + void Awake() { - _orbital = GetComponent(); + _orbital = GetComponent(); _axisController = GetComponent(); - if (_orbital == null) - Debug.LogWarning("[CameraOrbitKeyboard] CinemachineOrbitalFollow not found on this GameObject."); + } + + void OnEnable() + { + // On gère la souris nous-mêmes + if (_axisController != null) _axisController.enabled = false; + LockCursor(); + } + + void OnDisable() + { + UnlockCursor(); + } + + void LockCursor() + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + void UnlockCursor() + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; } void Update() { if (_orbital == null) return; - // Enforce cursor lock while this script is active (Player hierarchy is active = in gameplay) - if (Cursor.lockState != CursorLockMode.Locked) + var mouse = Mouse.current; + + // Clic droit = toggle lock + if (mouse != null && mouse.rightButton.wasPressedThisFrame) { - Cursor.lockState = CursorLockMode.Locked; - Cursor.visible = false; + if (Cursor.lockState == CursorLockMode.Locked) + UnlockCursor(); + else + LockCursor(); } - // Freeze camera orbit (keyboard + mouse) when keybind menu is open - if (KeyBindingUI.IsVisible) + if (KeyBindingUI.IsVisible) return; + + // Souris — seulement quand locked (delta infini, sans accrochage au bord) + if (Cursor.lockState == CursorLockMode.Locked && mouse != null) { - if (_axisController != null && _axisController.enabled) - _axisController.enabled = false; - return; - } - else if (_axisController != null && !_axisController.enabled) - { - _axisController.enabled = true; + Vector2 delta = mouse.delta.ReadValue(); + _orbital.HorizontalAxis.Value += delta.x * mouseSensitivity; + _orbital.VerticalAxis.Value = Mathf.Clamp( + _orbital.VerticalAxis.Value - delta.y * mouseSensitivity, + _orbital.VerticalAxis.Range.x, + _orbital.VerticalAxis.Range.y + ); } + + // Clavier var kb = Keyboard.current; if (kb == null) return; - // Physical-key mapping: W/A/S/D positions = Z/Q/S/D on AZERTY Key kUp = KeyBindingUI.GetKey("CamUp", Key.W); Key kDown = KeyBindingUI.GetKey("CamDown", Key.S); Key kLeft = KeyBindingUI.GetKey("CamLeft", Key.A); @@ -61,10 +93,10 @@ public class CameraOrbitKeyboard : MonoBehaviour if (kb[kUp].isPressed) v += 1f; if (kb[kDown].isPressed) v -= 1f; - if (Mathf.Abs(h) > 0.001f || Mathf.Abs(v) > 0.001f) + if (h != 0f || v != 0f) { _orbital.HorizontalAxis.Value += h * horizontalSpeed * Time.deltaTime; - _orbital.VerticalAxis.Value = Mathf.Clamp( + _orbital.VerticalAxis.Value = Mathf.Clamp( _orbital.VerticalAxis.Value + v * verticalSpeed * Time.deltaTime, _orbital.VerticalAxis.Range.x, _orbital.VerticalAxis.Range.y