From 8ccd003b00115488433cc79f9a99b43b9912b851 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Mon, 5 Sep 2022 20:09:34 +0100 Subject: [PATCH] limit fov range --- scripts/OrbitCamera.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/OrbitCamera.cs b/scripts/OrbitCamera.cs index feac7d0..55280e5 100644 --- a/scripts/OrbitCamera.cs +++ b/scripts/OrbitCamera.cs @@ -5,9 +5,10 @@ public class OrbitCamera : Spatial { [Export] private float _lookSensitivity = 200f; - [Export] private float _zoomSensitivity = 10f; + [Export] + private Vector2 _fovRange = new Vector2(10, 60); [Export] private NodePath _cameraPath; @@ -65,9 +66,18 @@ public class OrbitCamera : Spatial } } - private void Zoom(float amount) + private void Zoom(int dir) { - Camera.Fov += amount * _zoomSensitivity / Camera.Fov; + if (dir != 1 && dir != -1) + throw new ArgumentException(); + + var fov = Camera.Fov; + var zoom = _zoomSensitivity / Camera.Fov; + + fov += (float)dir * zoom; + fov = Mathf.Clamp(fov, _fovRange.x, _fovRange.y); + + Camera.Fov = fov; } private void HandleMouseMovement(InputEventMouseMotion mouseMotion)