V4NTT4BL4CK
Member
I've been working on this prototype minigame to learn how to use Game Maker Studio 2, but I have a problem that I don't have with other '' walls '' or colliding objects ...
when I jump to the roof or platform, my character should stop and return to the ground when he touches the object but returns when he has already crossed the middle of the platform
This is my code for gravity:
if (!collision_rectangle(x-8,y,x+8,y+1,obj_block, false,false)) {
gravity = 0.10;
image_index = spr_Jump;
}
if (vspeed > 0) {
var ground = collision_rectangle(x-8,y,x+8,y+vspeed,obj_block, false,false);
if (ground) {
y = ground.y;
vspeed = 0;
gravity = 0;
}
} else if (vspeed < 0) {
var ceiling = collision_rectangle(x-8,y-0,x+8,y-0+vspeed,obj_block,false,false);
if (ceiling) {
y = ceiling.y + ceiling.sprite_height + 25;
vspeed = 0;
}
}
And this is my code for jump:
if (keyboard_check_pressed(vk_space) && collision_rectangle(x-8,y,x+8,y+25,obj_block, false,false)) {
vspeed = -10;
image_index = spr_Jump;
}
when I jump to the roof or platform, my character should stop and return to the ground when he touches the object but returns when he has already crossed the middle of the platform
This is my code for gravity:
if (!collision_rectangle(x-8,y,x+8,y+1,obj_block, false,false)) {
gravity = 0.10;
image_index = spr_Jump;
}
if (vspeed > 0) {
var ground = collision_rectangle(x-8,y,x+8,y+vspeed,obj_block, false,false);
if (ground) {
y = ground.y;
vspeed = 0;
gravity = 0;
}
} else if (vspeed < 0) {
var ceiling = collision_rectangle(x-8,y-0,x+8,y-0+vspeed,obj_block,false,false);
if (ceiling) {
y = ceiling.y + ceiling.sprite_height + 25;
vspeed = 0;
}
}
And this is my code for jump:
if (keyboard_check_pressed(vk_space) && collision_rectangle(x-8,y,x+8,y+25,obj_block, false,false)) {
vspeed = -10;
image_index = spr_Jump;
}