A Checkpoint
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 20 of 27.
A checkpoint changes where the spikes send you. So the start point becomes a variable at the top of main.gd, where every function can reach it:
var start_point = Vector2(80, 280)
func _on_spikes_body_entered(body):
body.position = start_pointThe spikes send you to whatever start_point holds at that moment. Change the variable, and the next hit sends you there.
Change it with start_point = .... Writing var start_point = ... inside a function makes a new variable that exists only in that function. The one at the top stays the same.
Challenge
MediumWhen you reach the flag:
- Set
start_pointto the checkpoint's position,$Checkpoint.position. - Turn the flag mint:
$Checkpoint.modulate = Color(0.49, 0.95, 0.75).
Touch the flag, then the spikes. You should come back at the flag.
Try it yourself
extends Node2D
var start_point = Vector2(80, 280)
func _ready():
$Spikes.body_entered.connect(_on_spikes_body_entered)
$Checkpoint.body_entered.connect(_on_checkpoint_body_entered)
func _on_spikes_body_entered(body):
body.position = start_point
func _on_checkpoint_body_entered(body):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Signals and Collisions
Practice on your own: Godot playground