How to go in same door back and forth

Whenever I go in the same door to another area it works, but when I try going back to the same door to my previous area it creates a 0.3 milisecond flash to the previous area but doesn’t enter that area.

I don’t want to create another door and want just 1 door to work.

When the first event gets triggered does it move the Main_Character into a position that makes the 2nd event trigger? Both events could be triggering. Or maybe it’s another event.

Yes when I interact with the door first time it teleports me to the area I want. But when interacting with the same door again from the area that I am now teleported to, it just flashes and doesn’t teleport me.

I have realised that both events are triggering at the same time but I just wanted to see if someone can help overcome that by using just 1 door.

The way I dealt with teleporting portals/doors was to use a boolean variable (I called it “IsTeleporting”).

Put all the teleporting objects into an object group.

The variable is set to false when the player is not in collision with the teleport group.

When the player is in collision with a teleport group object, only teleport them if IsTeleporting is false. Before you teleport however, set the IsTeleporting to true.

Something like:

Conditions:
[inverted]Player in collision with TeleportGroup

Actions:
Set Variable IsTeleporting of object Player to false


Conditions:
Player in collision with TeleportGroup
Player.IsTeleporting is false

Actions:
Set Player.IsTeleporting to true
Change player position to the OtherTeleporter object
1 Like

Hey I think your issue is that both of your events don’t have any cooldown and just execute fast enough that when you press the a key it completes the conditions for both your actions.

Why does it do it only when using one of the doors ?
As you probably know gdevelop event sheet is readen by the engine from top to bottom which means an event that is above another will trigger first. Meaning that if you are close to “RedHouse” and press a it will move you to the new position. But from that new position you will be close enough to “Red_House_Door” to be able to teleport from there too which will teleport you back to “RedHouse2”.

However if you were to first teleport from “Red_House_Door” you would notice that the event takes place after the RedHouse one which means it will be able to only execute the Red_House_Door in the time the a Key is held down.

How to fix your issue ?

There are plenty of ways to counter this:

-using a boolean or number variable, when the a key is pressed and if the variable Teleporting == false then change the position and set the variable to true. Bellow all the actions you currently have, add a new one that says : If Teleporting == true then set Teleporting to false.

  • Another way would be to use a timer. At the beggining of the scene instantiate the scene timer “Teleportation”. In both the conditions for a key pressed add a new condition called “If scene timer “Teleportation” is > 0.5” So that way you will only be able to teleport if it has been 0.5 seconds since the game started. After this add the start/reset a scene timer as a action of both the teleportation scripts so that it starts the timer over again when teleporting so that it checks again if the cooldown was met

My tips and tricks :

  • First of all I would realy recommend you to be consistent in your objects names as well as you Variables names. “RedHouse2” doesn’t have any space or _ but “Red_House_Door” doesn’t look alike at all. It can create issues and bug later on when you code bigger projects.

  • When checking for a key input don’t use “ key is pressed” instead use “ key is releaed” What does it change ? When checking for pressed it will set the condition to true for the entire time you are holding the key on your keyboard. When using released instead it only checks the condition once when you release the key. It realy depends on the effect you’re trying to achieve but in your scenario it makes alot more sens to use key released as well as in 90% of cases

I found a solution by adding in key released, instead of key pressed like you suggested thank you so much.

I wanted to try the variable approach like @Angrill0n and @MrMen said but when I first tried the key released approach it instantly worked.

Here was the thing that worked for me if anyone wants to know:

Glad I could help, you should still consider the aspects I explained to you so that you know how to fix a similar error in the future

1 Like

And that solution is fine if you don’t mind the slight response delay in the teleporting action compared to moving. There’s a small and subtle change in the way keys work - for movement it’s instant, as soon as the key is pressed there is a response. But for teleporting there’s a slight delay for the player, there’s no response when the key is pressed; the response occurs when the key is released.

1 Like

Will consider for future projects, thank you both.

2 Likes