extends CharacterBody3D
class_name Player
+##########
+# settings
+##########
-# player settings
@export_group("Movement")
-@export var walk_speed := 10.0
+@export var walk_speed := 8.0
+@export var dash_length := 10.0
@export var air_speed := 3.0
@export var acceleration := 50.0
@export_range(0.0, 10.0) var joystick_sensitivity_x := 4.0
@export_range(0.0, 10.0) var joystick_sensitivity_y := 2.0
+######
+# init
+######
@onready var _camera_pivot: Node3D = %camera_pivot
@onready var _camera: Camera3D = %camera
func _ready() -> void:
_camera_spring.spring_length = camera_distance
+
+
-
-func _physics_process(delta: float) -> void:
- _process_camera(delta)
- _process_player(delta)
-
+#######
+# input
+#######
func _unhandled_input(event: InputEvent) -> void:
# If user clicks on the window, capture the mouse and direct the camera with it
_camera_input_method = CAMERA_MOUSE_INPUT
_camera_input_direction = event.screen_relative * mouse_sensitivity
elif event is InputEventJoypadMotion:
+ # TODO: add these settings!
_camera_input_method = CAMERA_JOYSTICK_INPUT
_camera_input_direction = Input.get_vector("camera-left", "camera-right", "camera-up", "camera-down")
_camera_input_direction *= Vector2(joystick_sensitivity_x, -joystick_sensitivity_y)
func _input(event: InputEvent):
if event.is_action_pressed("player-dash"):
_skin.transition_dash()
+ _player_dash()
elif event.is_action_pressed("player-slash"):
_skin.sword_visible()
_skin.transition_slash()
elif event.is_action_pressed("player-shoot"):
_skin.gun_visible()
_skin.transition_gunfire()
+
+
+##########
+# movement
+##########
+
+func _physics_process(delta: float) -> void:
+ _process_camera(delta)
+ _process_player(delta)
# Get the XZ input direction based on player's input relative to the camera
velocity += get_gravity() * air_speed * delta
move_and_slide()
+
+#########
+# actions
+#########
+
+func _player_dash():
+ var move_direction := _get_player_move_direction()
+ if move_direction != Vector3.ZERO:
+ var dash_local_pos = move_direction * dash_length
+ # TODO: check if valid position, crop the vector to last valid position
+ global_position += dash_local_pos