Adding Classic-style movement to your platform enemies.

2

Index

Stats

14,828 visits, 42,657 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

STEP 3

Movement

This is where we start to program our monster, so navigate to "Event Sheet 1".

First of all, we'll add an event to keep the detector attached to the monster. To do this, click 'Add event'. Select 'System' and then find 'Every tick'. This will tell the game to run the action every tick (approx. 60 times per second). The action will be as follows: Detector --> set position. A window should pop up asking you to put in an X coordinate and a Y. These coordinates are where we want to move the detector sprite. Enter "monster.ImagePointX("detector")" into the 'X' box and "monster.ImagePointY("detector")" into the 'Y' box, without the speech marks. The event sheet should now look something like this:

Hopefully you've got the hang of events by now, so from now on, I'll use a shorthand method of writing events. Going on the above example of an event, this is the syntax:

    System > Every tick = detector > set position (monster.ImagePointX("detector"), monster.ImagePointY("detector"))

If there are multiple conditions or actions, I'll use && to separate them. NOT symbolizes an inverted condition (right-click > 'invert') and ELSE is a 'System > Else' condition

So, let's finish the scripting. We need a few events that check whether the monster is at the edge of a platform, and then tell it to change direction if this is true:

    Detector > is NOT overlapping another object ("tile") && monster > is playing ("Right") = monster > set animation ("Left") && monster > simulate control ("Left")

    ELSE Detector > is NOT overlapping another object ("tile") && monster > is playing ("Left") = monster > set animation ("Right") && monster > simulate control ("Right")

This is what our event sheet looks like now:

Now, we'll add some more events that tell the monster to keep going along the platform, as long as he's not on the edge.

    ELSE Detector > is overlapping another object ("tile") && monster > is playing ("Right") = monster > simulate control ("Right")

    ELSE Detector > is overlapping another object ("tile") && monster > is playing ("Left") = monster > simulate control ("Left")

There, we've finished our event sheet!

If you click the small play button in the top left of construct 2, a test should run. Is the monster moving properly? If not, check back and make sure you got everything right!

Tips

- Select your monster in the layout tab, and in the properties bar, you can tweak the speed and acceleration of your monster to suit your game.

- Using the 'Animation Frames' window in the Sprite editor, you can give your monster a more realistic walking motion, rather than just changing the direction.

HOPE YOU FOUND THIS HELPFUL! PLEASE LEAVE A COMMENT!

GOOD LUCK IN YOUR GAME MAKING ADVENTURES!

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!