I need help figuring out teleporters.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SUPERFREAK

Hi ! I’m very new to Godot and Gamedev in general. I want to make a 2d game where you can click on one of your agents and set a destination room for them to go to. The problem is, I’m not sure how to program doors for my agents to go from room to room. The idea I had was that agents would enter the interaction state when theyre near a door and they are not at their destination, and they’d be teleported to the door’s target door, but how do I prevent the agent from reentering the interaction state right away ?

:bust_in_silhouette: Reply From: Entity2020 studios

You should use a Timer node and a boolean variable to control when the player is allowed to teleport. The variable can be named whatever you want, but for this answer I’ll call it ‘AllowTeleport’.

var AllowTeleport = true

Make sure to enable the ‘one shot’ setting for the timer node.
When the player is near a door, have the game check if the variable is set to ‘true’. If it’s set to ‘true’, then teleport the player, set the variable to ‘false’, and start the timer.

if AllowTeleport == true:
   AllowTeleport = false
   (Insert your teleportation code here)
   $Timer.start()

Have the timer broadcast the timeout() signal and make the game set the variable back to ‘true’ in response to the timer running out.

func _on_timer_timeout():
	AllowTeleport = true

Hope this helps!

yeah this seems helpful. Thanks !

SUPERFREAK | 2023-06-15 22:46