]> Untitled Git - knight.git/blobdiff - player/player.gd
Attacking added
[knight.git] / player / player.gd
index 1c483fa4bf22e5c99ebf689c90e11c98b77b0a04..f6b6c564fd09a213cfa0c63ff575aa412f7ab6ab 100644 (file)
@@ -1,7 +1,7 @@
 extends CharacterBody3D
 
 
-@onready var _skin: Node3D = $skin
+@onready var _skin: KnightSkin = $skin
 
 
 const SPEED = 5.0
@@ -15,17 +15,11 @@ var _last_movement_direction := Vector3.FORWARD
 func _input(event: InputEvent) -> void:
        if event.is_action_released("ui_accept"):
                velocity.y = 0
+       elif event.is_action_pressed("player-attack"):
+               _skin.attack()
 
 
-func _physics_process(delta: float) -> void:
-       # Add the gravity.
-       if not is_on_floor():
-               velocity += get_gravity() * FALL_SPEED * delta
-
-       # Handle jump.
-       if Input.is_action_just_pressed("ui_accept") and is_on_floor():
-               velocity.y = JUMP_VELOCITY
-
+func _process_player_input(_delta: float) -> void:
        # Get the input direction and handle the movement/deceleration.
        # As good practice, you should replace UI actions with custom gameplay actions.
        var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
@@ -38,10 +32,26 @@ func _physics_process(delta: float) -> void:
                velocity.x = 0
                velocity.z = 0
 
-       move_and_slide()
+       # Handle jump.
+       if Input.is_action_just_pressed("ui_accept") and is_on_floor():
+               velocity.y = JUMP_VELOCITY
+
 
+func _process_player_skin(_delta: float) -> void:
+       _skin.global_rotation.y = Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
+       
        if is_on_floor():
-               _skin.forward(velocity.length())
-               _skin.global_rotation.y = Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
+               _skin.move(velocity.length())
        else:
                _skin.fall()
+
+
+func _physics_process(delta: float) -> void:
+       # Add the gravity.
+       if not is_on_floor():
+               velocity += get_gravity() * FALL_SPEED * delta
+
+       _process_player_input(delta)
+       _process_player_skin(delta)
+       
+       move_and_slide()