- Home /
What is the best way to handle Off Screen Enemies in a SHMUP?
Hello,
I'm working on fixed position vertical scroller. The player's ship can't move off screen, rather the level comes to him. The best example of this is Art in Game's Air Attack HD. I'm also looking at a lot of classic arcade shooters like 1943. My question, How do those games handle off screen enemies?
In my current game build, I create triggers that are attached to a scrolling background. When the player goes through the trigger, an enemy spawns at an off screen trigger point. this kind of works, but the enemies sometimes appear in the middle of the screen, not really ideal. As it stands, I have to create a ton of triggers. Is there a better solution?
Answer by jmatthews · Mar 27, 2013 at 01:48 PM
I assume your visible screen clip is defined by a rect of some sort. If you're using an orthographic camera it will be defined by the orthographic size and then adjusted by your screen resolution. You want to hone in on that rect and use the far right bound and spawn mobs to the right of that.
If your scrolling speed is constant you can spawn waves of mobs based on time but that may complicate your level lay out. You can cut your number of triggers by having a single trigger begin a series of spawns(a wave) and then assign that wave to one trigger, and a different wave to the next trigger.
For offscreen spawning the easiest way I've found is to simply define a 2d bounding box that you're going to spawn mobs into and place it above(or in your case to the right) your viewport and high enough where the largest spawned mob is still not visible even if you spawn it at the nearest part of your bounding box.
My approach is code-centric and is simply a function of time. My scroll speed is constant so I simply spawn waves of mobs based on time and after a few playthroughs you get a feel for what spawn speed does to your level of difficulty. The benefit of this approach is that when you implement difficulty levels you can crank up the number of mobs easily as well as their strength.
Thanks! That definitely seems like a good alternative. Are you spawing enemies off of a timer on some type of game manager object? How do you keep track of all the mobs? ie 30 seconds instatiatie mob 1, 60 secs instantiate mob 2. Etc. Thanks for your help.
You're going to have to play with it and find something you like. This part of the design is the type of stuff that translates to the look and feel of the game and ends up defining what it is exactly that you've created.
I have a $$anonymous$$ob$$anonymous$$anager class that exposes a public gameobject spot for each mob type. Through the editor I link all my mobs(prefabs) on that script. Each mob shares a "mob" interface so I can keep them in a single list. This serves as a repository for all my mobs and all of the functions that act on them.
The mob responds to requests from an outside component(my Level$$anonymous$$anager)and serves up waves of mobs.
Internally(in the $$anonymous$$ob$$anonymous$$anager) I have two lists. One list holds instances of mobs that are deactivated so I'm not thrashing my garbage collector, and the other list is active mobs on screen at the moment. **edit - You could implement this as a single list pretty easily and may be just as good.
I have functions that run on my active mobs giving them a time slice for AI, movement, etc. and I cull these mobs against my screen rect to deactivate them when they've moved out of the play area or been destroyed.
$$anonymous$$y level manager is where I store stuff like difficulty and number of mobs in the level, and variables like "pace", "statboost" etc, that lets you dial up the challenge as need be.
That's a bunch to soak in but the fun part is you can do it a thousand other ways and still be right. Do what makes sense for you.
Thanks! You've given me a ton to think about. I will need to do some research into how to script this. Thanks again.
Answer by whydoidoit · Mar 27, 2013 at 02:25 PM
Well you would often do those based on a timer rather than triggers and you can work out what that timer would be based on the position of the object and the speed of the scrolling so that it is enabled just off screen.
You know - I really wouldn't move the background - just use a script fix the camera above the player and move it forwards (but not left and right) :)