extends CharacterBody3D
@onready var animation_crash = $Crash/Woah/AnimationPlayer
const SPEED = 4.7
const JUMP_VELOCITY = 6.5
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# 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")
# new vector3 direction, taking into account the user arrow inputs and camera rotation
var direction = ($"camera controler".transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
#rotate
if input_dir != Vector2(0,0):
$Crash/Woah.rotation_degrees.y = $"camera controler".rotation_degrees.y - rad_to_deg(input_dir.angle()) + 90
if direction:
if animation_crash.current_animation != "run":
animation_crash.play("run")
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
if animation_crash.current_animation != "idle":
animation_crash.play("idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
#make camera controller match the position of myself
$"camera controler".position = lerp($"camera controler".position, position, 0.25)