How can i use "await get_tree().create_timer().timeout" smoothly.

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

When it starts main scene, after it waits 2.5sec, i want to generate a pipe and move the pipe to x-axis. It repeats until game over. But my code made me different results looks like the following picture. How do i solve this problems?

:bust_in_silhouette: Reply From: crossbito

You are calling the function “timer” in every frame. I think what you want is to call that function only once in the “_ready” function, and then call “timer” inside the “create_timer” function to repeat it every 2.5 seconds.

In my opinion, you don’t need a timer to achieve this type of game. You could accomplish the pipe movement using an animation. Create a looping animation where you move the pipe as desired. When the pipe appears, change the starting frame of the animation to have a different pattern (to avoiding all the pipes moving in the same way.)

crossbito | 2023-06-08 17:48

In your answer, I turned my think that it’s better ways using timer node and signal. Anyway, thx for your opinion.

nagne | 2023-06-08 18:41