luna-lunatic/objects/player/player.gd
2025-11-01 21:27:15 -06:00

38 lines
855 B
GDScript

class_name Player
extends CharacterBody2D
@export var walk_speed: float
@export var stun_factor: float
@export_group("Internal References")
@export var _animations: AnimationPlayer
var stun_time: float = 0.0
func _physics_process(delta: float) -> void:
if stun_time > 0.0:
stun_time -= delta
else:
var input_dir = Input.get_vector(&"move_left", &"move_right", &"move_up", &"move_down")
velocity = input_dir * walk_speed
if input_dir.is_zero_approx():
_animations.play(&"idle")
else:
_animations.play(&"walk")
move_and_slide()
func knock(force: Vector2) -> void:
velocity = force
stun_time = force.length() / stun_factor
#func _on_hurtbox_body_entered(body: Node2D) -> void:
#if body is Groove:
#var dir = body.global_position.direction_to(global_position)
#velocity = dir * body.velocity.length()
#stun_time = 0.5