Note: this tutorial is out of date. You can use the concepts from this tutorial, combined with this tutorial http://gamefroot.com/knowledgebase/move-it-physics-movement-and-the-constantly-loop/ to recreate this.
An easy thing you can do to make your games more tricky to navigate is to add moving tiles. Static platforms can become boring and predictable, so why not keep the player on their toes? Here’s how we can make a moving tile.
First, make sure you’ve got your level drawn out with a nice big gap between some terrain. Remember that terrain tiles need to be drawn onto the tilemap layer.
Once you’ve got your terrain drawn, place your player character next to the gap. Make sure the player character is placed on the layer above the tilemap.
Then attach the Platform Player Controls script to the player character – if you don’t do this, you won’t be able to play!
Now for the moving tile. Grab an object from the Game Objects tab in the sidebar, and place it in the gap.
This object needs a script to tell it to move, so let’s make one. Click Script Edit Mode to create a new script (if you’re new to scripts, check this out). Here’s the script we need to make:
(If you want a close look, click on the image to zoom in.) This script is giving these instructions to the object:
- When created become immovable (so the player can’t knock me around), and give me a velocity x (horizontal speed) of 50.
- Constantly, if my x position is further than 1000, set my velocity x to -50 (so I will start travelling to the left if I’ve gone too far to the right).
- or else, if my x position is before 530, set my velocity x to 50 (so I will start travelling to the right if I’ve gone too far to the left)
And this makes the object move back and forth! To create this, we’ll need to start with 2 Event blocks called “When created” and “Constantly”, which we can find under Game Mechanics, Events.
Next we’ll need “Set velocity x” and “Set reacts to gravity” from the Arcade Physics tab. Drag these blocks into the “When created” block. Then click on “reacts to gravity” and change it to “immovable”.
Now we need to set up the logic for the movement, and we’ll do this with an “if, do” block from the Logic tab. Drag it into the “Constantly” block.
To turn the “if do” block into an “if do, else do” block, you’ll need to click on the star button in it’s top-left corner, and drag the “else if” block across. You can click on the star again to make that window go away.
Next we need the “less than” and “greater than” blocks from the Logic tab. Drag them into the “if” slots, and change the top = to ≥, and the bottom = to ≤.
Now grab two “x position of myself” blocks from the Instances tab, and drag them in the “less than” and “greater than” slots.
To put numbers into the empty “less than” and “greater than” slots, go to the Math tab and drag out the “0” number block.
The last two blocks are “set velocity x” from the Arcade Physics tab. Drag these into the “if do” and “else if do” openings. Change the numbers to -50 for the top one, and 50 for the bottom one.
Lastly, we need to figure out what the “greater than” and “less than” numbers need to be. We can determine these numbers by going back to our level and finding the positions on either side of the gap – but don’t forget to Save this script first (click the Save button in the top-right corner).
Once you’ve saved the script, click Close to return to your level. By hovering your mouse cursor over any part of your level, you can see what those x and y positions are inside your level – these numbers are displayed above the layers panel to the right (x position, y position). I can see that my gap starts at 530 x, and then by hovering over the other side of the gap, I can see that it ends at 1000 x.
Now that we know these numbers, we can go and add them to our script. Open the Scripts tab in the sidebar, and click Edit on your moving tile script.
Once your script has opened, change these numbers from 0 to the positions you determined just before. The top number should be the position of right side of the gap, and the bottom number should be the position of the left side of the gap. Once you’ve changed those numbers, save the script and close the script editor.
Now attach the script to the moving tile object by clicking on the script then clicking on the object.
All done! Now you can preview your game. Click the image below to see the game run:
Cool 😉
so coolllllllllllllllllllllllllllllllllllllllllllllllllllll
okkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
gool!
Update this please. It’s so annoying that i have to do a project and the new system has different features which get’s confusing. PLEASE!!
Please update, it’s so frustrating
good concept. i like the way you done it. you wrote every details in step by step. if you update it and work more with this game. I think it will be a great game.