#Checkpoints not working
4 messages · Page 1 of 1 (latest)
player code :
extends CharacterBody2D
const SPEED = 100.0
const JUMP_VELOCITY = -200.0
var checkpoint_position: Vector2 = Vector2(-220, 116) # Predvolená hodnota na začiatku hry
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func _ready() -> void:
position = checkpoint_position
func respawn():
position = checkpoint_position
func update_checkpoint(new_position: Vector2):
checkpoint_position = new_position
respawn() # Presunie hráča na nový checkpoint
killzone code :
extends Area2D
func _on_body_entered(hrac):
if hrac.name == "Hrac":
hrac.respawn()
checkpoint code :
extends Area2D
func _on_body_entered(hrac):
print("Hráč vstúpil do Checkpointu")
hrac.update_checkpoint(global_position)