GML - Moving Platforms



Requires Collision Correction activity to be completed (but not any questions or extension activities), as this activity continues on from the end of that example.



no new sprites other than those used in Collision Correction


in addition to the objects used in Collision Correction:

ObjectSpritePropertiesParent Object
objUpDownsprBlockVisible (make sure you also set parent object)objBlock
objLeftRightsprBlockVisible (make sure you also set parent object)objBlock

same room layout as Collision Correction activity but this time add a couple of (soon to be) moving platforms objUpDown and objLeftRight

//initial speed and dir:
//(+) = down, (-) = up:
vspeed = +2; 

//range from start location:
range_in_px = 50;
//move platform within range:

if (y >= ystart + range_in_px){
  vspeed = vspeed * -1;
}

if (y <= ystart - range_in_px){
  vspeed = vspeed * -1;
}

//if player is standing on this
//vertically moving platform:

inst = instance_place(x, y-1, objPlayer);
if (inst != noone)
  { inst.vspeed = vspeed; }
//initial speed and dir:
//(+) = right, (-) = left:
hspeed = +2; 

//range from start location:
range_in_px = 50;
//move platform within range:

if (x >= xstart + range_in_px){
  hspeed = hspeed * -1;
}

if (x <= xstart - range_in_px){
  hspeed = hspeed * -1;
}

//if player is standing on this
//horizontally moving platform:

inst = instance_place(x, y-1, objPlayer);
if (inst != noone)
  { inst.hspeed = hspeed; }

experiment with different ranges and speeds of platforms