dp-konzultace/addons/simple-portal-system/scripts/simple_portal_teleport.gd
2025-02-10 23:34:26 +01:00

26 lines
889 B
GDScript

"""
Asset: Godot Simple Portal System
File: simple_portal_teleport.gd
Description: An area which teleports a node through the parent node's portal.
Instructions: For detailed documentation, see the README or visit: https://github.com/Donitzo/godot-simple-portal-system
Repository: https://github.com/Donitzo/godot-simple-portal-system
License: CC0 License
"""
extends Area3D
class_name SimplePortalTeleport
var _parent_portal:Portal
func _ready():
_parent_portal = get_parent() as Portal
if _parent_portal == null:
push_error("The PortalTeleport \"%s\" is not a child of a Portal instance" % name)
connect("area_entered", _on_area_entered)
func _on_area_entered(area:Area3D):
if area.has_meta("teleportable_root"):
var root:Node3D = area.get_node(area.get_meta("teleportable_root"))
root.global_transform = _parent_portal.real_to_exit_transform(root.global_transform)