1 extends CharacterBody3D
4 @onready var _skin: Node3D = $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"):
20 func _physics_process(delta: float) -> void:
23 velocity += get_gravity() * FALL_SPEED * delta
26 if Input.is_action_just_pressed("ui_accept") and is_on_floor():
27 velocity.y = JUMP_VELOCITY
29 # Get the input direction and handle the movement/deceleration.
30 # As good practice, you should replace UI actions with custom gameplay actions.
31 var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
32 var direction := -(transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
34 velocity.x = direction.x * SPEED
35 velocity.z = direction.z * SPEED
36 _last_movement_direction = direction
44 _skin.forward(velocity.length())
45 _skin.global_rotation.y = Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)