diff --git a/project.godot b/project.godot index 354519d..3cc2cb9 100644 --- a/project.godot +++ b/project.godot @@ -59,31 +59,37 @@ import/blender/enabled=false move_forward={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) ] } move_back={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] } move_left={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) ] } move_right={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } jump={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } menu={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null) ] } toggle_fullscreen={ @@ -97,6 +103,26 @@ toggle_cursor_capture={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +camera_up={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) +] +} +camera_down={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) +] +} +camera_left={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) +] +} +camera_right={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) +] +} [layer_names] diff --git a/scenes/player.tscn b/scenes/player.tscn index 35b49c9..bb66317 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -23,6 +23,7 @@ properties/2/replication_mode = 1 [node name="Player" type="CharacterBody3D"] collision_layer = 2 script = ExtResource("1_82m0t") +_respawn_height = null [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) diff --git a/scenes/title.tscn b/scenes/title.tscn index 04ddbad..c0e74a4 100644 --- a/scenes/title.tscn +++ b/scenes/title.tscn @@ -92,5 +92,5 @@ grow_horizontal = 2 grow_vertical = 2 theme_override_colors/font_color = Color(1, 0.54, 0.54, 1) theme_override_font_sizes/font_size = 26 -text = "errors" +text = "here be errors" horizontal_alignment = 1 diff --git a/scripts/player.gd b/scripts/player.gd index 19f512f..c18cdc0 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -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)