Having the player stop taking inputs when level is transitioning

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

Hello, I am very new to game development and have been following through with some tutorials. I’ve finished one, but want to continue developing off the tutorial to make my first game, however, I’ve run into an issue.

I’m making a 2D Mario-like platformer, and at the end of the level, there is a portal to teleport the player to the next level.

I would like the player to become invisible and stop taking input once it hits the portal, because right now the transition is about a second long, and in that time the player can move around and potentially die to the enemies, which breaks the game a little. I think my biggest issue is not understanding signaling and having the 2 scripts (player and portal) working together.

I did try to make a ‘_on_PortalDectector_area_entered’ function, similar to how touching the enemies kills the player, but I’ve run out of ideas to make it work.

Any help or tips would be much appreciated.
Thanks

:bust_in_silhouette: Reply From: Inces

You need to introduce a state in which game behaves differently. Easiest way would be to pause your game when transition happens. You could simply set pause mode of transition effect to false, when everything else would be paused. On tansistion finished - unpause.
If you only want to hold inputs, than introduce some boolean variable or state, for example var transition : bool. Your trnasition start will set this var to true, trnasition finished - to false. In your players input function as a first line :

func _input(event):
       if transition == true: 
            return

I’ve spent some time with this, trying your methods to see if I can get it working. I can get the game to pause when the player touches the portal, but then it just freezes the game. I do have pause functionality, so I don’t know if that would mess with the ability to use pause here.
I think I understand the logic behind the boolean variable, however, I haven’t had any luck turning that into code. How would the code in the ‘Portal’ script stop inputs outlined in the ‘Player’ script? In other words, how to export the ‘transition’ function (in ‘Portal’) to work in the player script?

Wings | 2022-03-03 04:48

:bust_in_silhouette: Reply From: Wings

I’ve figured it out. I already had a variable in my player script that turned off inputs. And I finally remembered how signals worked. I was trying to signal the different scripts in their own independent folder and was trying to get those to interact. Where signals only allow nodes to interact. Until it occurred to me that they all were nodes in the ‘Level’ Scene.

From there, I clicked the ‘script’ buttons in the scene, added signals using the ‘node’ tab next to the inspector, and got this.

func _on_Portal2D_body_entered(body: Node) -> void:
	playing = false
	visible = false

Now ‘playing’ turns of inputs and ‘visible’ turns off the sprite, and the level transitions smoothly.