1 extends CharacterBody3D
4 @onready var _skin: Node3D = $skin
8 const JUMP_VELOCITY = 4.5
11 func _physics_process(delta: float) -> void:
14 velocity += get_gravity() * delta
17 if Input.is_action_just_pressed("ui_accept") and is_on_floor():
18 velocity.y = JUMP_VELOCITY
20 # Get the input direction and handle the movement/deceleration.
21 # As good practice, you should replace UI actions with custom gameplay actions.
22 var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
23 var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
25 velocity.x = direction.x * SPEED
26 velocity.z = -direction.z * SPEED
28 velocity.x = move_toward(velocity.x, 0, SPEED)
29 velocity.z = move_toward(velocity.z, 0, SPEED)
34 _skin.forward(velocity.length())
35 _skin.global_rotation.y = Vector3.FORWARD.signed_angle_to(direction, Vector3.UP)