• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Moving platforms

M

Michael Franklin

Guest
I have a character named judy:
Code:
/// @description City physics

//input
left = keyboard_check(ord("A"));
right = keyboard_check(ord("D"));
jump = keyboard_check_pressed(vk_space);

//Movement
var move = right - left;

hsp = move * walksp;


vsp = vsp + grv;

//jump
if (place_meeting(x,y,ocity)) or (place_meeting(x,y,oplat1)) or (place_meeting(x,y,oplat2)) and (jump){

}

//Horrizontal collision
if (place_meeting(x+hsp,y,ocity)){
    
    while (!place_meeting(x+sign(hsp),y,ocity)){
        
        x = x + sign(hsp);
    }
    hsp = 0;
    
}
x = x + hsp;

//Verticalcollision
if (place_meeting(x,y+vsp,ocity)){
    
    while (!place_meeting(x,y+sign(vsp),ocity)){
        
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y = y + vsp;
In one of the rooms she will fight enemies on a platform called ocity:
Code:
/// @description Float

y = anchor_y + sin(timer*frequency)*amplitude;
timer+=1;
The city slowly floats up and down. My issue is that when Judy is on the platform she slowly falls threw the collision box of the platform because it moves up and down. How do I keep her on top of the collision box when it moves up and how do I keep her on the collision box when moving down. I don't want gravity pushing her down with it, I would like her to stay with it. Eventually she will be able to jump so when it goes up and down she should still be able to do normal actions such as jumping and attacking.
 

NightFrost

Member
The platform has to push and pull all riders above it by the amount it moved. That is, everyone it can touch at collision y - 1 and whose bbox_bottom is above its bbox_top so those in process of jumping through it don't get caught for a ride. It needs to do this before the riders check their movements and apply their gravities, so in Begin Step.
 
M

Michael Franklin

Guest
The platform has to push and pull all riders above it by the amount it moved. That is, everyone it can touch at collision y - 1 and whose bbox_bottom is above its bbox_top so those in process of jumping through it don't get caught for a ride. It needs to do this before the riders check their movements and apply their gravities, so in Begin Step.
I put my collision code into the begin step event and it didnt work. Im new to game maker studio 2 so I dont know all the lingo. What is bbox_bottom and bbox_top. What do they do and do I need them in my code, if so where and why?
 

NightFrost

Member
What's the code you wrote for the platform? The various bbox_* things (top, bottom, left, right) are builtin instance variables that tell you where the edges of its collision box are. When a character jumps from below and moves up through the platfrom, the check I described makes sure the platform grabs and moves only those standing on top of it, instead of those in process of jumping through it. And it actually should also have a direction check so it doesn't snag characters just past it, but best worry about those things only after you've got the platform itself working properly and moving characters riding it.
 
M

Michael Franklin

Guest
What's the code you wrote for the platform? The various bbox_* things (top, bottom, left, right) are builtin instance variables that tell you where the edges of its collision box are. When a character jumps from below and moves up through the platfrom, the check I described makes sure the platform grabs and moves only those standing on top of it, instead of those in process of jumping through it. And it actually should also have a direction check so it doesn't snag characters just past it, but best worry about those things only after you've got the platform itself working properly and moving characters riding it.
I only have this code to make it float, the platform does nothing else
Code:
/// @description Float

y = anchor_y + sin(timer*frequency)*amplitude;
timer+=1;
and this is my collision code for judy when interacting with the collision box of the platform
Code:
/// @description

//Horrizontal collision
if (place_meeting(x+hsp,y,ocity)){
    
    while (!place_meeting(x+sign(hsp),y,ocity)){
        
        x = x + sign(hsp);
    }
    hsp = 0;
    
}
x = x + hsp;

//Verticalcollision
if (place_meeting(x,y+vsp,ocity)){
    
    while (!place_meeting(x,y+sign(vsp),ocity)){
        
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y = y + vsp;
 

TheouAegis

Member
My method of handling moving platforms is to store the platform's id in the player. When the player jumps, set the id to noone. Every End Step, check if a platform's id is saved and then snap the player's y using y+=saved_platform.bbox_top-bbox_bottom. For horizontal movement, you should have a horizontal vector (like hspeed) in the platform for the player to read.
 
M

Michael Franklin

Guest
My method of handling moving platforms is to store the platform's id in the player. When the player jumps, set the id to noone. Every End Step, check if a platform's id is saved and then snap the player's y using y+=saved_platform.bbox_top-bbox_bottom. For horizontal movement, you should have a horizontal vector (like hspeed) in the platform for the player to read.
Do you mean something like this?
Step:
Code:
/// @description City physics

//input
left = keyboard_check(ord("A"));
right = keyboard_check(ord("D"));
jump = keyboard_check_pressed(vk_space);

//ocity id
city_id = layer_get_id(ocity);
city_layer = instance_create_layer(x,y,city_id,ocity)

//Movement
var move = right - left;

hsp = move * walksp;


vsp = vsp + grv;

//jump
if (place_meeting(x,y+1,ocity)) and (jump){
    city_layer = false;
    vsp = -7;
}
Begin step:
Code:
/// @description

//Horrizontal collision
if (place_meeting(x+hsp,y,ocity)){
    
    while (!place_meeting(x+sign(hsp),y,ocity)){
        
        x = x + sign(hsp);
    }
    hsp = 0;
    
}
x = x + hsp;

//Verticalcollision
if (place_meeting(x,y+vsp,ocity)){
    
    while (!place_meeting(x,y+sign(vsp),ocity)){
        
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y = y + vsp;
End step:
Code:
/// @description

if (city_layer == false){
    y+=ocity.bbox_top-bbox_bottom;
}
 

TheouAegis

Member
city_layer = instance_create_layer(x,y,city_id,ocity)
Not this. When you are fallimg and detect a collision with ocity, set city_layer to the id id the ocity you collided with. Then in your end step code, change ocity.bbox_top to city_layer.bbox_top to snap to that instance's bbox_top.
 
Top