Browsed by
Category: News

Spawning System Overhaul and overcoming the obstacle of enemy pattern making

Spawning System Overhaul and overcoming the obstacle of enemy pattern making

The Grid

Wow, it’s been a while, but things are moving forward slowly but surely!

I’ve been busy with lots of coding and programming enemies and i encountered some difficulties in proper positioning. On the image below you can find how the spawn points looked (5 spheres on each side) and how they look now (the red X signs)

Spawning Grid
Obviously, 12 times more spawning points offer much more flexibility

Obviously, it offers much more in terms of positioning. More than a year ago, when i first started working on a spawn system i wasn’t apt enough to make it the way i wanted to (grid system) so i had to be satisfied with only a few spawn points and additional repositioning upon instantiating. Needless to say, it adds much more work to simple spawning and positioning of those enemies.

By using this handy tool from the asset store (https://www.assetstore.unity3d.com/en/#!/content/20502) i created a grid made out of objects completely automatic. A fine tool indeed. After that, i simply added those to the hash table and now i can simply reference the object whose position i want the enemy to use as spawn point and voila. Besides using it to spawn enemies already in a pattern, i can use them to actually create random patterns on runtime by referencing a different object from the hash table upon predefined parameters to avoid completely random clutter. Not only that, a finer grid enables me to avoid spawning the enemies too close to each other or overlap. Since i’m using Core Game Kit for spawning, i’m waiting for the developers to implement the feature based on sphere raycasting, i.e. if there’s an object of certain tag or layer (enemy) in a defined range, the system won’t spawn any more to avoid the overlapping. It will work great with the system i made and described few devlogs earlies which is based on enemy pool values and enemy quantities.

Also, Easy Save 3 Beta will soon get a full release (i hope VERY SOON) which will enable IMPORTING variables from a .csv file. It will be of an immense help for tweaking the gameplay.

Enemy Pattern Making (Squadrons)

I must admit, though i am passionate about making a game, some things are quite tedious. I’m having problems with making enemy squadrons, and the way i make them is so boring and uninspiring it really halts my progress.

Before i was well into Unity engine limitations on nested prefabs (only one child per object, i.e. child cannot have it’s own child as a prefab, only when instantiated on runtime due to way serialization works) i thought it was going to be a breeze, i just drag and drop enemies in a formation, put them under a parent prefab and voila! Except it doesn’t work like that. All of my enemy prefabs typically have two children, Gunpoint and Thruster. Gunpoint hold the shooting logic and muzzle flash animation, while Thruster has the, well, thruster animation. It is on a separate object to avoid being colored with the rest of the enemy ship when it changes color on hit by a player weapon.

So i guess i’ll keep my work and make an empty squadron prefab which will spawn and then spawn the enemies in a desired pattern coded into it. That’s all nice and dandy until you actually start working that way. No more cosy drag and drop, just selecting what to spawn, input coordinates and hit play too see what you’ve done. If something’s not positioned correctly (it usually isn’t), reposition the enemy, copy the coordinates, stop, and paste them. Repeat 10 times for 10 enemy objects in a squadron, and i should have hundreds of them! Horrible!

Prefab and Runtime comparison
Prefab with multiple children with position setting on runtime

So i decided to change my ways. I need to make a reverse approach. Instead of creating an enemy prefab with all the children attached, i’ll attach the Gunpoint and Thruster on instantiation, which is only a two step process compared to setting the position of multiple enemies inside the squadron. This way, i have a clean enemy prefabs without children which i can joyfully drag and drop into positions i want and simply save them under a prefab which will be used for spawning.

Prefab and Runtime Setting 2
Prefab with multiple children instantiating on runtime

Though it is a bit more work initially, it provides an immense saving of time later and makes it more visual, fun and intuitive to work with.

Backgrounds work

Backgrounds work

I bought this little fella (http://www.wacom.com/en-br/products/pen-tablets/one-wacom-m) a while ago but i never found time to play around with it. This weekend was very hot so i was mostly home and i’ve drawn a background for the game, hope you dig it. Took me a few hours.

Background

Dev Log #2

Dev Log #2

It’s been almost two weeks and i’ve been very busy with my day job so i didn’t manage to spare too much time for game, but i finally finished (for me) a very complicated thing – upgrade and weapon switching system.

Player starts out with one weapon. During the game he can pickup a variety of weapons from destroyed cargo ships. The first time he picks up a weapon, it is added as a second weapon, and player can switch between them according to situation (bullet, energy and missile weapons don’t deal the same amount to normal, armored and shielded enemies). When another weapon appears as a pickup, two scenarios are possible: if the weapon is already equipped, it gets upgraded and the pickup despawns. If the weapon is already at maximum upgrade level, player is notified via on-screen message and the pickup stays where it is. If the weapon is not equipped, currently selected weapon is replaced (dropped as a pickup, while pickup spawns on player). While dropping the weapon is not very important in single player game and complicates the situation a lot, it is handy in 2 player game, where one player can drop a weapon for the other player to upgrade his weapon. The handy thing is that when a player drops, for example, Hyperblaster Level 4 and the other player picks it up, he’ll get the Level 4 Hyperblaster too, not level 1. Since there are (for now) 23 weapons in game and the only way to upgrade them (besides universal weapon upgrade pickups) is to pickup the same weapon, that will be very cool in terms of player cooperation.

Here’s a shot of an FSM:

Spaghetti coding
Spaghetti coding

Basically, when the weapon spawns, it checks itself if it is a weapon or a pickup (by checking if it is parented or not). If it is a weapon, that means that it is player equipped and it is added to the array and the variable is stored if it is in slot one or slot two (required for weapon switching during the game). If it is a pickup, distance check state is activated. Player can only pick it up if he is closer than a defined distance from it (by pressing space, so no accidental pickups are possible). When he picks it up, it iterates through the array to see if it will replace the existing weapon (if no weapon of same type is found) or upgrade it (if weapon of same type is found). If it replaces it, the existing weapon is dropped (which means it is despawned, removed from array, spawned on location of a pickup with its firing scripts disabled and pickup indicator enabled, while next level weapon is spawned on gunpoint with its firing scripts enabled and pickup indicator disabled).
Weapon switching is, compare to the upgrade and pickup system, a walk in the park. Stored weapons are simply activated/deactivated by pressing the switch key.

Scripting this thing alone would probably take a lot more time than it did, so using Playmaker did the job pretty quick since i can try something out in a matter of seconds, not waiting to write a couple of lines with risk of making syntax errors.

But, here comes the downside. Instead of making the script that can just be copied/pasted on all weapons (have in mind that there are 23 weapon with 3-5 levels each, so that comes to about a hundred prefabs, with more to come), i have to copy/paste an FSM to every weapon and tweak the variables in each one of them. I don’t have to tell you that if any larger scale fixes in logic are necessary when all the weapons are already prepared it will be a lot of work to change everything. Not to mention the possibility of making errors when managing such a tedious task.

One more thing i did is implementing the sprite atlas which reduced draw calls a lot, and boosted frame rate from 15-30 FPS to ~150. Now everything goes very smoothly. There are some hiccups, but those are due to extensive logging which is quite necessary in this phase. Swarm missiles got an overhaul too, now they’re flying nicely in a semi-random homing pattern, they way i imagined them to be.

Swarm missiles flying nicely in a semi-random homing manner
Swarm missiles flying nicely in a semi-random homing manner

Also, the artist guy did some weapons art for me, some will maybe change, but i thing they’re pretty good looking and quite different.

A selection of collectable weapons
A selection of collectable weapons
Dev Log #1

Dev Log #1

To keep the track of the work done, motivate myself and keep people interested, it’s time to start a Dev Blog. Here’s the first one for the work done in the last few days, enjoy.

  1. Design of the Swarm Missiles weapon. Basically (as the name says) it launches a swarm of small missiles from the player ship and every one of them tracks random enemy. It may require an overhaul to make them more random with some sort of unnecessary crazy loops to compensate for their number. The design wasn’t too tough, each missile has a random frontward direction upon launch and a small delay before tracking starts. Every few moments, they change the target they locked on to so they move randomly in a natural, swirly manner.
  2. Design of the Randomizer (work title) weapon which shoots a lot of particles but to compensate for their number they move slowly in a random forward pattern and are fairly weak, but can protect you from swarms of smaller enemies. Pretty useless against big enemies though.
  3. Design of the Shield with regeneration timer and connection to the shield integrity bar. Still needs connecting to the heat transfer mechanism (when you get hit, shield takes the damage, but your heat level increases, energy transfer stuff).
  4. Design of the Auto Cannon Drone. It tracks closest enemy, rotates towards it and fires. If no enemies are present, it stops firing. Oh, it also follows player of course.
  5. Design of the Ripper, basically a manual shooting shotgun that sprays multiple bullet in a cone, that was pretty easy to make. It shoots as fast as you can click, deals a lot of damage it all bullets hit the target, but it heats a lot, so i have to disappoint you if you’re a Starcraft player with million clicks per minute and plan to win the game using Ripper only.
  6. Design of the Flak Cannon. Like the real Flak, it has proximity activated “fuse”. At a certain distance from the enemy it explodes and blasts into a lot of small pellets. Great against small enemies.
  7. Design of the Proximity Mines. Regular mines just floating in space were designed a while ago, but i decided to put a bit more challenging ones. When you get near one, it shoots a laser ray which locks on to your ship (doesn’t damage it though) and starts slowly moving towards you until you destroy it. I also designed the EMP mines that will work the same way, but deal less damage and messĀ up your screen with glitch effects. Also updated the mines with random rotation and blinking red light so they’re a bit more interesting looking and easier to spot.

 

Dev Blog - Guided Mines
Homing Mines – slow but deadly
Presenting the Paragons

Presenting the Paragons

Paragons are mysterious faction of occultists that use phase shifting and cloaking ships based on that funny yellow balls full of energy.

Paragons
Hard to hit something when it constantly changes it’s position, right?