M
Michael Franklin
Guest
I have a character named judy:
In one of the rooms she will fight enemies on a platform called ocity:
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.
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;
Code:
/// @description Float
y = anchor_y + sin(timer*frequency)*amplitude;
timer+=1;