I’m creating an on-rails 3D space shooter akin to Star Fox. I would like enemies to spawn in certain locations and fly along a certain path, some toward the player and some from behind the player, as if they are flying along an unmoving, unchanging “string” that I have drawn in the world. Spawning the enemies is easy: Set up a trigger box somewhere along the level and simply detect when the player enters it. The tough part for me is telling the enemies how and where to fly, when to fire their weapons, etc.
I’m not looking for code, at least not right now. I’m just trying to conceptualize how this will be done.
Look up how to make 3D splines, they’ll give you smooth on-rails movement as long you place control points a consistent apart and have crazy tangents. I think there are assets on the asset store that offer that kind of functionality, in particular for camera movement. For detecting when to shoot, you can have a Shoot() method you can invoke in Start() with a random delay, then invoke again within itself with another random delay:
public void Start() {
Invoke("Shoot",Random.Range(minShotDelay,maxShotDelay));
}
public void Shoot() {
//check if we can shoot, and if so
//fire laser, play sound
Invoke("Shoot", Random.Range(minShotDelay,maxShotDelay));
}