How to spawn objects on timer?

So I am very new to game development and coding in general. I am trying to write code and make stuff myself, but immediately I stumbled on this problem

It’s test flappy bird game, right now I’m trying to spawn pipes on timer, but it spawns only one pipe and then does nothing

var pipes_scene = preload ("res://pipes.tscn") 
var can_add_pipes:bool = true

func _process(delta):
	if can_add_pipes:
		var pipes = pipes_scene.instantiate()
		$pipes.position.x = $pipespawn.position.x
		can_add_pipes = false
	$pipes.position.x -= 100 * delta
func _on_timer_timeout(delta):
	can_add_pipes = true

I’ve searched for an answer, but found only godot v3 forums and guides

upd: I am stupid, but I’ve found out that bool in can_add_pipes simply doesn’t change. It works when I export it to inspector and manually turning it on and off

I also forgot to start timer.

Now I need to know how to change bool

upd2: I am VERY stupid. It appears that it wants to spawn same pipes over and over. It doesn’t want to make new pipes. Now I have NO idea what in the world am I doing

pls help

Aloa Ghostu,

I definately recommend you first follow the beginners tutorial of the docs for 2D.

Do you even know what $pipes does? Its Shorthand for get_node("pipes") which means get me the Node with the name “pipes” in my tree. But the name has to be unique, so you just changing the position of the same Node.

Every pipe should handle their own position in _process(delta) of your pipes Scene or even clearer the script attached to that scene.

While maybe sounding a bit harsh, I wish you a lot of fun learning and welcome to the community.

Kind regards,

1 Like

I see. Now that makes sense why I don’t see new pipes spawning


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.