add controller movement
This commit is contained in:
@@ -30,10 +30,12 @@ func _ready() -> void:
|
||||
_camera.make_current()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
velocity = Vector3.ZERO
|
||||
func _process(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
_process_respawning()
|
||||
_process_controller_rotating(delta)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -54,25 +56,43 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
if event is InputEventMouseMotion:
|
||||
var mouse_event := event as InputEventMouseMotion
|
||||
var sensitivity := deg_to_rad(Settings.mouse_sensitivity)
|
||||
_handle_mouse_rotating(event as InputEventMouseMotion)
|
||||
|
||||
rotate_y(
|
||||
(
|
||||
-mouse_event.screen_relative.x
|
||||
* sensitivity
|
||||
* (-1 if Settings.invert_mouse_horizontal else 1)
|
||||
)
|
||||
)
|
||||
|
||||
_camera.rotate_x(
|
||||
(
|
||||
-mouse_event.screen_relative.y
|
||||
* sensitivity
|
||||
* (-1 if Settings.invert_mouse_vertical else 1)
|
||||
)
|
||||
)
|
||||
_camera.rotation.x = clamp(_camera.rotation.x, -PI / 2, PI / 2)
|
||||
func _process_respawning() -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
velocity = Vector3.ZERO
|
||||
|
||||
|
||||
func _process_controller_rotating(delta: float) -> void:
|
||||
var controller_raw_input := (
|
||||
Input
|
||||
. get_vector(
|
||||
"camera_left",
|
||||
"camera_right",
|
||||
"camera_up",
|
||||
"camera_down",
|
||||
)
|
||||
)
|
||||
|
||||
rotate_y(
|
||||
(
|
||||
-controller_raw_input.x
|
||||
* deg_to_rad(Settings.controller_sensitivity_horizontal)
|
||||
* delta
|
||||
* (-1 if Settings.invert_controller_horizontal else 1)
|
||||
)
|
||||
)
|
||||
_camera.rotate_x(
|
||||
(
|
||||
-controller_raw_input.y
|
||||
* deg_to_rad(Settings.controller_sensitivity_vertical)
|
||||
* delta
|
||||
* (-1 if Settings.invert_controller_vertical else 1)
|
||||
)
|
||||
)
|
||||
_camera.rotation.x = clampf(_camera.rotation.x, PI / -2, PI / 2)
|
||||
|
||||
|
||||
func _lateral_movement(delta: float) -> void:
|
||||
@@ -106,3 +126,24 @@ func _vertical_movement(delta: float) -> void:
|
||||
func _jumping(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = JUMP_FORCE
|
||||
|
||||
|
||||
func _handle_mouse_rotating(event: InputEventMouseMotion) -> void:
|
||||
var sensitivity := deg_to_rad(Settings.mouse_sensitivity)
|
||||
|
||||
rotate_y(
|
||||
(
|
||||
-event.screen_relative.x
|
||||
* sensitivity
|
||||
* (-1 if Settings.invert_mouse_horizontal else 1)
|
||||
)
|
||||
)
|
||||
|
||||
_camera.rotate_x(
|
||||
(
|
||||
-event.screen_relative.y
|
||||
* sensitivity
|
||||
* (-1 if Settings.invert_mouse_vertical else 1)
|
||||
)
|
||||
)
|
||||
_camera.rotation.x = clamp(_camera.rotation.x, -PI / 2, PI / 2)
|
||||
|
||||
Reference in New Issue
Block a user