From: Clifton Palmer Date: Sun, 4 May 2025 08:47:25 +0000 (+0300) Subject: Added player dash X-Git-Url: http://git.purplebirdman.com/frog-ninja.git/commitdiff_plain/9a1efe8c169a1d08c3537d4e21eae27866d5e9c8 Added player dash --- diff --git a/player/player.gd b/player/player.gd index d00302d..d08f491 100644 --- a/player/player.gd +++ b/player/player.gd @@ -1,10 +1,13 @@ 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 @@ -23,6 +26,9 @@ class_name Player @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 @@ -43,12 +49,12 @@ var _player_speed: float = walk_speed 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 @@ -60,6 +66,7 @@ func _unhandled_input(event: InputEvent) -> void: _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) @@ -68,12 +75,22 @@ func _unhandled_input(event: InputEvent) -> void: 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 @@ -156,3 +173,14 @@ func _process_player(delta: float) -> void: 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 diff --git a/texture/grid.png b/texture/grid.png index f7cc6f2..7cc12f7 100644 Binary files a/texture/grid.png and b/texture/grid.png differ