diff options
Diffstat (limited to 'WorldCamera.cs')
| -rw-r--r-- | WorldCamera.cs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/WorldCamera.cs b/WorldCamera.cs index 77fa7cb..6675fac 100644 --- a/WorldCamera.cs +++ b/WorldCamera.cs @@ -14,6 +14,9 @@ public partial class WorldCamera : Camera3D private float ct = 0.5f; //time to reach destination [Export] private float rotateSpeed = 2f; //radians per second + [Export] + private float mouseSensitivity = 0.005f; + private bool midDrag = false; private enum Mode { @@ -35,9 +38,33 @@ public partial class WorldCamera : Camera3D } } + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseButton mb && mb.ButtonIndex == MouseButton.Middle) + { + midDrag = mb.Pressed; + } + else if (@event is InputEventMouseMotion motion && midDrag) + { + // Horizontal orbit + offset = offset.Rotated(Vector3.Up, -motion.Relative.X * mouseSensitivity); + + // Vertical orbit around the axis perpendicular to offset in the XZ plane + Vector3 right = Vector3.Up.Cross(offset).Normalized(); + if (right.LengthSquared() > 0.001f) + { + Vector3 newOffset = offset.Rotated(right, -motion.Relative.Y * mouseSensitivity); + // Clamp to prevent flipping over top or going below horizontal + float angle = newOffset.AngleTo(Vector3.Up); + if (angle > 0.15f && angle < Mathf.Pi * 0.85f) + offset = newOffset; + } + } + } + public override void _Process(double delta) { - float rotInput = Input.GetAxis("cam_rotate_right", "cam_rotate_left"); + float rotInput = Input.GetAxis("cam_rotate_cw", "cam_rotate_ccw"); switch (mode){ case Mode.Follow: |
