1 extends CharacterBody3D
4 @onready var _skin: KnightSkin = $skin
8 const JUMP_VELOCITY = 4.5 * 3
12 var _last_movement_direction := Vector3.FORWARD
15 func _input(event: InputEvent) -> void:
16 if event.is_action_released("ui_accept"):
18 elif event.is_action_pressed("player-attack"):
22 func _process_player_input(_delta: float) -> void:
23 # Get the input direction and handle the movement/deceleration.
24 # As good practice, you should replace UI actions with custom gameplay actions.
25 var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
26 var direction := -(transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
28 velocity.x = direction.x * SPEED
29 velocity.z = direction.z * SPEED
30 _last_movement_direction = direction
36 if Input.is_action_just_pressed("ui_accept") and is_on_floor():
37 velocity.y = JUMP_VELOCITY
40 func _process_player_skin(_delta: float) -> void:
41 _skin.global_rotation.y = Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
44 _skin.move(velocity.length())
49 func _physics_process(delta: float) -> void:
52 velocity += get_gravity() * FALL_SPEED * delta
54 _process_player_input(delta)
55 _process_player_skin(delta)