UFO's spawn at the top and bottom of the screen and follow a predetermined path. We will create a UFOSpawner scene to spawn UFOs.
Create a new scene with Node as root
Add a new Path2D as child renamed to PathTop
Add a Path2D as a child renamed to PathBottom
Add a PathFollow2D as a children of both
Add a Timer and rename to UFOTimer
Position it at the top of the screen
Create a path of points for the UFO to move between you do not have to copy my pattern
Position it at the bottom of the screen
Create a path of points for the UFO to move between you do not have to copy my pattern
Attach a script to customize it
Export the min and max wait time vars
Create a function to setup the timer
Create a variable to get a random timeout value
Set the wait time to the timeout value
Now attach a script to the UFOSpawner
Create an export var for the UFO scene
Create ready vars for:
TopPath
BottomPath
UfoTimer
How do Paths and PathFollows work?
In Godot, objects cannot just "float" along a curve. They need a vehicle.
This is just a drawing. It has no physical form. It defines WHERE you can go (the curve), but it cannot move anything itself.
This is the physics engine. It snaps magnetically to the tracks. It has a special engine called progress that decides WHEN to move.
Sprite / Area2D (The Passenger):
This is the art. It sits inside the Cart. It doesn't know where the track is; it just knows it is sitting at (0,0) inside the Cart.
Create a function to spawn a ufo
Randomly pick either the top or bottom path
Now create the cart for the path
Instantiate the Ufo scene
Add the cart to the track
Connect the timeout signal
By picking the spawn_ufo function
Now Add both Spawners to the Main scene