moving platforms up & down | gml
Add a new object objMovingUpDownBlock use the same sprite as the objBlock and set parent:

Again, if you need a wider platform, make a wider sprite (don't stack objMovingUpDownBlock objects side by side):

code for step event | gml
Updated 2025: Simply add the following code to STEP event in vertical moving platform:if place_meeting(x,bbox_top-1, objPlayer){ //height cap: if y > (ystart - 200){ vspeed = -1; objPlayer.y += vspeed; } else { vspeed = 0; } } else { //return to start: if (y < ystart) { vspeed = 1; } else { vspeed = 0; } }
The code above should be all you need, works in conjunction with Platform Collision Correction code (first lesson)
older code (outdated - ignore) from previous years | gml
objMovingUpDownBlock Create
going = "up"; range = 200; //px move_speed = 3;
objMovingUpDownBlock Step
if (going == "up"){ y = y - move_speed; if (y <= ystart - range) going = "down"; } else { y = y + move_speed; if (y >= ystart + range) going = "up"; } //this assumes origins are top left: if place_meeting(x, y-move_speed, objPlayer) and going == "up" { objPlayer.y = y - objPlayer.sprite_height; } //the drop / gap is quicker down: if place_meeting(x, y-move_speed*2, objPlayer) and going == "down" { objPlayer.y = y - objPlayer.sprite_height; }^ Note the above gml code for objMovingUpDownBlock →
Step
event below assumes sprite origins have been left at top left (0,0)
You can also adjust the instances of the platforms individually in the room editor using the creation code...

... but the quickest way of adjusting instance variables in the room, allowing you to reuse objects quickly:


Challenges
1. Implement the above code2. Adjust the
move_speed
and range
variables. How fast and far can this go that is feasible for general gameplay (for the 'average' gamer)?3. Set out a new level with moving platforms using the skills you have learnt so far. Make it increasingly challenging to get from one side of the room to the other (with timed jumps etc.)
4. Make an elevator using this knowledge. Give the elevator an on / off switch or trigger (difficult).