Having some trouble with move_and_collide

Godot Version

Godot v4.6.2.stable

Question

Hello. Trying to make a basic Flappy Bird clone and having trouble using move_and_collide() to make the pipes move. Here is my pipe.gd:

extends AnimatableBody2D

var speed = 200

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#	position.x -= speed * delta
	var velocity = Vector2.LEFT * speed * delta
	move_and_collide(velocity)

func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	self.queue_free()

func reset():
	self.queue_free()

And here is where I spawn pipes in main.gd:

func _on_pipe_spawner_timeout() -> void:
#	spawn bottom pipe
	var pipe = pipe_scn.instantiate()
	$Pipes.add_child(pipe)
	
	var random_height = randi_range(100, screen_size.y - 50)
	pipe.position.x = screen_size.x
	pipe.position.y = random_height

#	spawn top pipe
	var pipe_top = pipe_scn.instantiate()
	$Pipes.add_child(pipe_top)
	
	pipe_top.position.x = pipe.position.x + 15
	pipe_top.rotation = PI
	pipe_top.position.y = pipe.position.y - 125

The top pipes scroll across the screen from right to left as expected, but the bottom pipes flash on screen for a frame or two then disappear. I can’t tell if they’re moving too fast to see or immediately despawning. In the pipe.gd on line 11 you can see a commented out line where I set the position of the pipe manually, and that leads to the expected movement for all pipes, but I’d like to be able to detect collisions inside pipe.gd by using move_and_collide, so this won’t work for me.

Any ideas on how to fix the movement of the bottom pipes when using move_and_collide? And more importantly, why is the behavior different for the top and bottom pipes? I appreciate your help!

Just realized it was an issue with collision layers and masks after browsing through some other threads here. I have a ground object that was colliding with the bottom pipes and making them go haywire. I fixed this by setting the collision mask for the pipe to 2 (and deselected 1), and added collision layer 2 to the bird object.