Hello! I’m trying to make a portal, but it just won’t work. I know that the issue is that the portals never deactivate or stop teleporting when the player enters the portal, but I’m not sure on how to stop it. Here is my code:
(They have the same script and same on_body_entered signal connected to themselves)
Could anybody give me an idea of how to make it so that the player doesn’t instantly teleport when it reaches the other portal? I also tried a timer, but it’s causes more problems. Any help is appreciated!
Since I don’t know exactly how your things are set up, I can only suggest a very generic solution. In your case, I would simply set up a flag (or a bool variable) inside the player object. Let’s call this variable has_teleported. When any of your teleports detect _on_body_entered with the player, set has_teleported to true, then teleport the player. In the same teleport code, simply check if has_teleported is true, and if it is, even if you detect the player, don’t teleport them, then simply add the _on_body_exited signal, and when that’s triggered for the player, simply set has_teleported to false, so they can teleport again when they go back and touch your teleporter once more.
Hello! Sorry if I wasn’t clear enough. What exactly do you need? I tried something similar to this, but this wouldn’t work. I have a video of the issue if you need it:
I’ve looked at some other tutorials with 2 way portals, and they don’t instantly teleport the player back. Do you have another idea of something that might work? Thanks so much for your response!
Hello! Thank you so much! This works perfectly! It looks like I was applying the teleport_available to the portal the player is going through, not the destination. Thank you!
The issue still isn’t 100% clear to me, but in your setup, is the destination one is teleported to, directly where the second teleport is?
If so, setting a bool, or cooldown value should be anle to provent instant teleporting back.
If that’s not the setup, could you provide some more information?
Yes, when you enter portal 1, you go directly into portal 2. The problem was that the player was spawning right on top of the portal 2 collision shape, making the player teleport to portal 1, causing a loop of not being able to exit the portal. Thankfully it’s solved! Thank you for your response!