Platform-Style Video Games with Construct

Interacting with Enemy Characters

Your browser needs to be JavaScript capable to view this video

Try reloading this page, or reviewing your browser settings

The video shows how to write events that enable the player character to interact with the enemies.


  • Construct 2
  • Non-player characters

About this video

Lee Stemkoski
First online
15 February 2019
Online ISBN
Copyright information
© Lee Stemkoski 2019

Video Transcript

Lee Stemkoski: Now we want the Koala to interact with the enemy, so let’s close the preview. And let’s add some more events. The way the Koala can defeat an enemy is if it falls on top. So let’s add an event. This event will be a Koala condition, we’ll check if it’s overlapping another object. Click to choose, that object is the Enemy and it will check to see if the Koala Is falling. That will indicate it’s jumped on top of the enemy. Let’s right click that condition and Add another condition. This will be a Koala condition. We want to check if the Koala Is falling. That’s in the Platform category, Is falling.

In this case, the enemy’s destroyed. So the first action is an Enemy action. Under the miscellaneous category, we’ll destroy. As a second action, we’ll give the Koala a little bit of a bounce after it collides with the enemy in this way. So let’s add a second action. This is a Koala action, kind of similar to the springboard action we set up before. This is in the Platform category. To give the Koala of boost upwards, we’re changing its velocity in the Y direction, so we’ll choose the action Set vector Y. We’ll change that maybe to negative 400, that’ll be a little boost upwards.

Finally, if the Koala is overlapping the enemy in any other way, for instance, if it walks into the enemy or hits the enemy from below, that will cause damage to the Koala, so we’ll add an event to take care of that. Clicking on Add event, let’s select Koala. And Next, Is overlapping another object. As before, we’ll click to choose the Enemy. We’ll add a second condition too. Similar to when the Koala was overlapping the spikes, the Koala will flash, indicate both damage has been taken and a state of temporary invincibility.

So this second event should only happen if the Koala is also not flashing. Let’s add a second condition by right clicking, Add another condition, Koala, and under the Flash category, choose Is flashing. Then right click that condition and from the pop-up menu, select Invert. So if the Koala hits the enemy, it’s not falling if we’re at this point. Let’s add an action to first, lose 1 Health point. So this is a variable related action, so it’s under System, under Global and local variables. Choose Subtract from, subtract from Health, the value 1. And as a second action, we’ll make the Koala flash. So this is a Koala action. Under Flash, let’s activate flash. Let’s change the duration to 2 seconds. That’ll give us enough time to get out of harm’s way.

With these events added, let’s save and give this a test first. We’ll try taking damage by jumping into the enemy from below. Right now, we have 3 Health. If I jump into the enemy from below, I can time this. Sure enough, I went down to 2 Health and the Koala started flashing. Now let’s see if I can jump onto the enemy from above. Time this just right. All right, that destroyed the enemy, had a little bit of a bounce as I fell down. So that enemy mechanic works fairly well.

If you’d like to add additional enemies, let’s go back to the layout. It’s as easy as a duplicating an object I could duplicate and put another enemy up here. You also want to set the boundaries by creating copies of the MoveLeft and MoveRight boundaries. For instance, you could have the enemy protecting a key. In addition, you can change this to the other enemy type. So for instance, if I’d like to create a slime enemy, maybe I’ll take this block and move this down here. Opposition my MoveLeft and my MoveRight on these two locations/ I’ll put my fly down on the ground and then under the Properties, I’d like to change the initial animation from the default, which is the fly animation since that’s the first one we added. Let’s change that to slime. S-l-i-m-e is what we named the other one. And now this slime will appear to go back and forth between these two blocks. I might also reduce the speed of the slime. It goes a little bit slower. Maybe I’ll change that to 75.

Now let’s give this a test. We’ll save, and press play once again, so we should see two different enemies, a fly moving back and forth near the top of the screen and a slime which appears to be going back and forth in the bottom of the screen. With each of these enemies, we should be able to both take damage if we run into it and jump on top to destroy the enemy. Excellent. So now you have a variety of hazards. In addition to the spikes on the ground, you have some mobile enemies. We should add a good deal of challenge to your game.