How do I make a obstacle spawning thing for a jetpack joyride clone

Godot Version

4.3

Question

I wanna spawn the lasers randomly going right and delete them when they go off the screen how can I do that (btw incase if it was unclear the lasers are static)

You can create new nodes and add them to the scene with add_child(). You can delete nodes with queue_free(). If you have a fixed camera and are moving the nodes, you can keep an eye on node.global_position.x to see when they’re far enough away to delete. See the rand...() functions for how to generate random numbers.

You can make things move in their _process() function by adding their speed (or the camera speed…) multiplied by the delta argument to each thing’s “x” position.

There are lots of ways you could do this:

  • level full of stuff, camera sliding over it
  • fixed camera, background and objects moving
  • fixed camera, moving background nodes with objects attached to them