- Edited
I'm trying to create a mechanic that makes the player return to the last cell he touched before falling into a killzone
the system works I tested it as follows
LastcollidedTileMap.gd
extends Area2D
@onready var collision = $CollisionShape2D
func _on_body_exited(body):
if body.name == "TileMap":
Global.last_position_before_jump = collision.global_position
killzone.gd
extends Area2D
@onready var timer = $Timer
var player = null
func _on_body_entered(body):
print("You Died!")
player = body
timer.start()
func _on_timer_timeout():
player.global_position = Global.last_position_before_jump
The problem is if the player stays on the edge of the cell
it will respawn on the edge obviously and this can make the player die easily
my idea is to obtain the central position of the last cell that the player stopped touching based on the location of "collision"