39 lines
1.0 KiB
GDScript

extends Level
const ACCELERATION := 6.0
var speed := 4.0
var velocity := Vector2.ZERO
var target_velocity := Vector2.ZERO
@onready var model: Shambler = %Shambler
@onready var speed_label: Label = %SpeedLabel
func _ready() -> void:
model.play_spawn_animation()
func _unhandled_input(event: InputEvent) -> void:
if event.is_action("select_next_tool"):
speed = min(speed + 0.1, 40)
elif event.is_action("select_prev_tool"):
speed = max(speed - 0.1, 0)
elif event.is_action("jump"):
model.play_spawn_animation()
func _physics_process(delta: float) -> void:
var move_input := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
target_velocity = move_input * speed
velocity = velocity.lerp(target_velocity, 1 - exp(-ACCELERATION * delta))
if velocity:
model.set_target_rotation(atan2(velocity.x, velocity.y))
var real_speed := velocity.length()
speed_label.text = "%.2f" % real_speed
model.set_move_speed(real_speed)
model.global_position += Vector3(velocity.x, 0, velocity.y) * delta