@@ -2,16 +2,17 @@ class_name FreelookCamera3D extends Camera3D
2
2
3
3
@export var movement_speed := 10
4
4
@export var mouse_sensitivity := 0.006
5
+ @export var fov_change_speed := 50.0
5
6
6
7
var _previous_camera : Camera3D
7
8
var _camera_input_direction := Vector2 .ZERO
8
-
9
+ var _target_fov : float
9
10
10
11
func _ready () -> void :
11
12
current = false
12
13
process_mode = PROCESS_MODE_ALWAYS
13
14
set_process (current )
14
-
15
+ _target_fov = fov
15
16
16
17
func _input (event : InputEvent ) -> void :
17
18
if event .is_action_pressed ("toggle_freelook_camera" ):
@@ -25,6 +26,11 @@ func _input(event: InputEvent) -> void:
25
26
if is_camera_motion :
26
27
_camera_input_direction = event .relative * mouse_sensitivity
27
28
29
+ if event is InputEventMouseButton :
30
+ if event .button_index == MOUSE_BUTTON_WHEEL_UP :
31
+ _target_fov = max (_target_fov - 1 , 1 )
32
+ elif event .button_index == MOUSE_BUTTON_WHEEL_DOWN :
33
+ _target_fov = min (_target_fov + 1 , 179 )
28
34
29
35
func _process (delta : float ) -> void :
30
36
var movement := Vector3 .ZERO
@@ -49,11 +55,13 @@ func _process(delta: float) -> void:
49
55
50
56
_camera_input_direction = Vector2 .ZERO
51
57
58
+ fov = move_toward (fov , _target_fov , delta * fov_change_speed )
52
59
53
60
func _toggle_camera_mode () -> void :
54
61
if not current :
55
62
_previous_camera = get_viewport ().get_camera_3d ()
56
63
fov = _previous_camera .fov
64
+ _target_fov = fov
57
65
global_transform = _previous_camera .global_transform
58
66
make_current ()
59
67
else :
0 commit comments