Menu
CoddyTech

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 icon

Challenge

Easy

Send whoever touches the spikes back to the start.

  1. In _on_body_entered(body), set the position of body, not of the spikes.
  2. Set it to Vector2(80, 280).

Press Play and walk into the spikes: you are back at the start. Then Check.

Try it yourself

extends Area2D

func _ready():
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	pass

All lessons in Signals and Collisions

Practice on your own: Godot playground