TheOnlyWRT
Member
Hey guys, so i am making a platformer game and the next feature i would like to add is moving platforms, both vertical and horizontal. I have already got jump through platforms working, and have used that as the basis. Horizontal platforms are working great, but i cant get vertical ones to work. When the player lands, he just falls right through the platform.
Here is the player collision code:
And here is the moving platform code:
Thanks!
Here is the player collision code:
Code:
var vspFinal = vsp+vspCarry;
vspCarry = 0;
//check for a vertical collision before moving the player
var wall = place_meeting(x, y+vspFinal, objectFloorParent);
//if(Wall || (JumpThrough && vsp > 0 && bbox_bottom < JumpThrough.bbox_top)){
if(wall){ //this is a normal collision
while(!place_meeting(x, y+sign(vspFinal), objectFloorParent)){
y = y + sign(vspFinal);
}
vspFinal = 0;
vsp = 0;
}
//check for a jump through platform
var jumpThrough = place_meeting(x, y + vspFinal, objectJumpThrough);
if(jumpThrough){ //this is a jumpthrough platform
if((vspFinal >= 0) && (!place_meeting(x, y, objectJumpThrough))){ //we are moving down and should collide
while(!place_meeting(x, y+sign(vspFinal), objectJumpThrough)){
y = y + sign(vspFinal);
}
vspFinal = 0;
vsp = 0;
}
}
Code:
//////////////////////
// MOVEMENT
//////////////////////
vsp = movesp*dir;
//check for a collision with an invisible block
if(place_meeting(x, y+vsp, objectFloorInvisible)){
while(!place_meeting(x, y+sign(vsp), objectFloorInvisible)){
y = y + sign(vsp);
}
dir = dir*-1;
}
//check for a vertical collision before moving the player
if(place_meeting(x, y+vsp, objectFloorParent)){
while(!place_meeting(x, y+sign(vsp), objectFloorParent)){
y = y + sign(vsp);
}
dir = dir*-1;
}
//move the player
y = y+vsp;
if(instance_exists(objectPlayer)){
if(place_meeting(x, y-1, objectPlayer)){
objectPlayer.vspCarry = vsp;
}
}
Thanks!