Spikes Send You Back
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 19 of 27.
A hazard is an area that hurts. Here a hit sends you back to the start. The spikes' function gets the body that touched them, and you can change that body like any node. Set its position:
func _on_body_entered(body):
body.position = Vector2(80, 280)body.position is the player's position. A plain position is the spikes' own, and setting it would move the spikes.
The start is the faint square at (80, 280), bottom left.
Challenge
EasyWhen a body touches the spikes, send it back to the start, (80, 280). Walk into the spikes to try it.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_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