how to create a countdown timer to make the game start

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

Hey there everybody,
so some context
when i press the play button from the main menu,
it will go to the game level,
when that happens i want a 3 second countdown timer to countdown to zero before the player can actually play the level,
best example i can think of is the countdowntimer in sonic air riders on the ps2 that would count down before the player could begin the race, only i want the player to only be able to play the game after the 3 second countdown,
what i have:
is a control node, then child to that is the label node, then child to that is a timer node,
when the timer reaches zero i also want it to disappear from the screen so a temporary countdown timer as well.

i hope that all made sense,
thank you!

:bust_in_silhouette: Reply From: Mxt08

for the timer countdown I leave you with a link that I think can help you:
Timer CountDown

For the part where the player can’t play until the countdown is over, I recommend pausing the game and putting the timer on the pause process mode tab, and that when that time has passed, start the game and you change the visibility of the timer (this is done by putting in the code the name of the node that represents the timer and adding to it .visibility = hidden or invisible) and it would be done.
I hope these tips help you.
Mxt08 :slight_smile:

:bust_in_silhouette: Reply From: Okan Ozdemir

You just need to write before load scene

func _ready():
    yield(get_tree().create_timer(2), "time_out")
    Change_scene_to("dada/your level.tscn")
:bust_in_silhouette: Reply From: Magso

There are two main ways of doing this. There are ways of doing it using the timer node but I’ve personally found it to be unnecessarily awkward.

Mxt80’s answer but in code

func _ready():
    get_tree().paused = true
    yield(get_tree().create_timer(3), "timeout")
    get_tree().paused = false

Or make the player ignore any movement until a timer runs out.

var timer = 3.0

func _process(delta):
    if timer > 0:
        timer -= delta
        #player code
:bust_in_silhouette: Reply From: zen3001

use the Timer node.
add it as a child node to your level.
set it’s wait time property to 1 second.
go to the signals tab of the node and connect the timeout() signal to what ever script you want to use for it, just make sure you can access the timer node from the script.
in the script create an integer variable with the value of 3.
in the signaled function, reduce the value of your variable by one, check wether it’s reached 0 and if not, restart the timer, else you can start the game.

the script then should look something like this:

func timeout_signal():
countdown -= 1
if not countdown == 0:
	$Label.text = str(countdown)+"!!!"