From f27937e6e9b6a7146dd09fc711d2d293ecf5abbf Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 14 Apr 2024 21:49:20 +0200 Subject: update --- Scenes/Components/Teleport.gd | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Scenes/Components/Teleport.gd (limited to 'Scenes/Components/Teleport.gd') diff --git a/Scenes/Components/Teleport.gd b/Scenes/Components/Teleport.gd new file mode 100644 index 0000000..03e900f --- /dev/null +++ b/Scenes/Components/Teleport.gd @@ -0,0 +1,26 @@ +extends Node2D + +class_name Teleport + +@export_node_path("Teleport") var target: NodePath + +var targetNode: Teleport + +# Called when the node enters the scene tree for the first time. +func _ready(): + self.targetNode = get_node(self.target) + + self.targetNode.get_node("Leave").connect("body_exited", _on_body_exited) + + +func _on_body_entered(body): + if body is Player: + var player: Player = body + + (func(): self.targetNode.get_node("Enter/CollisionShape2D").disabled = true).call_deferred() + player.position = self.targetNode.position + + +func _on_body_exited(body): + if body is Player: + (func(): targetNode.get_node("Enter/CollisionShape2D").disabled = false).call_deferred() -- cgit v1.2.3