freettrpg/scripts/player.gd

27 lines
541 B
GDScript3
Raw Normal View History

2024-06-13 13:29:05 +02:00
extends CharacterBody2D
@export var speed = 200
var toCalculate = position
var distanceTo = 0
var active = false
2024-06-13 13:29:05 +02:00
func get_input():
var input_direction = Input.get_vector("left", "right", "up", "down")
velocity = input_direction * speed
func _physics_process(delta):
if active:
get_input()
move_and_slide()
distanceTo = position.distance_to(toCalculate)
if distanceTo > 500 and active:
active = false
$camera.enabled = false
get_parent().next()
func start():
$camera.enabled = true
active = true
toCalculate = position