Back to Top

Hi there! My name is Victor Menzing, aka VMG 206, and I am a programmer.

I started this site because I want to teach people how to build nice games without writing a lot of code.

Tutorials

Fighting Enemies

It is time to add some enemies to our level! Fortunately, the 2D Game Kit includes the needed graphics and code for two different enemies, which look good and are quite easy to set up and customize.

Open your level, and the double click the "Enemies" folder in the Project view; you will see the two prefab enemies, just like in the image below.

enemies 1Drag a Chomper to the level, and then tweak its position, making sure that it is properly aligned with the floor level. Then, run the scene and try to stay alive; otherwise, you will be greeted by a panel that looks like this one ;)

game overOur enemy is a bit too aggressive for such a small level, wouldn't you agree? So, let us dumb it down a little bit. Stop the game, and then click the Chomper to explore its properties in the Inspector view. Make sure that you are using the Move Tool (activate it using the "W" key) to select the enemy.

Fortunately, all the parameters that interest us are grouped in the "Enemy Behavior" section.

enemy behaviorLet's set "Speed" to 0.5; this will reduce our enemy's speed to 50%. Then, set a "View Fov" of about 100 degrees; that value is set to 360 degrees now, thus allowing the Chomper to see the player even if it approaches the enemy from behind. Finally, set "View Distance" to 3. All these changes will be visible in the Scene view as well - see for yourself.

enemy settings 1Run the level again; you will see that our aggressive Chomper behaves much more nicely now. You can add as many Chompers as you want to the game, of course.

It's time to add the second enemy to our level. Drag a Spitter into the scene; you will see that its "View Fov" is way too big, so make sure to reduce it to about 80 degrees. Let's set this guy's "View Distance" to 4, thus allowing the player to come much closer to it without triggering its devastating attack.

Run the game and you will discover that the Spitter fires green, poisonous balls which will reduce player's health really fast.

enemies 2Fortunately, the player can fight back. Use the "S" key to crouch, and thus get to the player to a proper height. Then, fire your blaster using the "O" (not zero!) key.

blasterThat's it for now, folks! Build a nice level, and then explore all the extra moves, features, bonuses and level elements; I promise that you'll find quite a few! Okay, let's uncover another one: you can crouch (S), and then press the jump key (space) to pass through special platforms, and thus reach lower areas of your level. You will need to add a "PassThroughPlatform" prefab to the scene, but I am sure that this won't be a problem for you.

Here's how this great feature looks in my level.

passthrough