-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer_camera.gd
More file actions
34 lines (26 loc) · 875 Bytes
/
player_camera.gd
File metadata and controls
34 lines (26 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class_name PlayerCamera
extends SpringArm3D
const MOUSE_ROTATION_SPEED := 0.002
const ZOOM_SPEED := 0.5
@onready var _camera: Camera3D = $Camera
var _captured: bool
func _ready() -> void:
if is_multiplayer_authority():
_camera.current = true
else:
set_process_input(false)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cursor"):
if _captured:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
_captured = !_captured
elif event.is_action_pressed("zoom_in"):
spring_length += ZOOM_SPEED
elif event.is_action_pressed("zoom_out"):
spring_length -= ZOOM_SPEED
elif _captured and event is InputEventMouseMotion:
rotation.y -= event.relative.x * MOUSE_ROTATION_SPEED
rotation.x -= event.relative.y * MOUSE_ROTATION_SPEED
rotation.x = clamp(rotation.x, -PI / 2, 0.7)