Skip to content

Commit d19c6dc

Browse files
Move head rotate input to top layer scripts
1 parent 6b16631 commit d19c6dc

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

addons/character-controller/example/main/player.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ func _physics_process(delta):
2727
input_fly_mode = !input_fly_mode
2828
move(delta)
2929

30+
# Called when there is an input event
31+
func _input(event: InputEvent) -> void:
32+
# Mouse look (only if the mouse is captured).
33+
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
34+
rotate_head(event.relative)
35+
3036
func _on_controller_emerged():
3137
camera.environment = null
3238

addons/character-controller/fps/fps_controller_3d.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func setup():
4242
func _check_head_bob(_delta):
4343
head_bob.head_bob_process(horizontal_velocity, input_axis, is_sprinting(), is_on_floor(), _delta)
4444

45+
func rotate_head(mouse_axis : Vector2) -> void:
46+
head.rotate_camera(mouse_axis)
47+
4548
func move(_delta: float):
4649
if is_fly_mode() or is_floating():
4750
direction_base_node = head

addons/character-controller/fps/head_movement.gd

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class_name HeadMovement
77

88
@export var mouse_sensitivity := 0.002
99
@export var vertical_angle_limit := 90.0
10-
var mouse_axis := Vector2()
1110
var rot := Vector3()
1211

1312

@@ -19,15 +18,7 @@ func set_vertical_angle_limit(limit : float):
1918
vertical_angle_limit = deg_to_rad(limit)
2019

2120

22-
# Called when there is an input event
23-
func _input(event: InputEvent) -> void:
24-
# Mouse look (only if the mouse is captured).
25-
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
26-
mouse_axis = event.relative
27-
_camera_rotation()
28-
29-
30-
func _camera_rotation() -> void:
21+
func rotate_camera(mouse_axis : Vector2) -> void:
3122
# Horizontal mouse look.
3223
rot.y -= mouse_axis.x * mouse_sensitivity
3324
# Vertical mouse look.

0 commit comments

Comments
 (0)