Cant make jump in gamemaker studio2

557 Views Asked by At

I can't make the jump work in my game made in game maker studio 2 this project uses gravity and the game maker's language.

this is now just random words so stack overflow lets me post this question so Minecraft is a cool game :).

here is the code:

/// @description this is the create event

// You can write your code in this editor

sprite_index=Sprite1;
image_speed = 1;
image_index = 0;

step event:

    /// @description Insert description here
// You can write your code in this editor

#region //gravedad 
if place_free(x,y+1){

gravity =1;

}else{

gravity=0;

}

if vspeed >=20{vspeed=20}

#endregion

#region //movimiento
if keyboard_check(ord("D")){

direction=0
speed = brr;


}
else{

speed=0;

}

if keyboard_check(ord("A")){

direction=180
speed = brr;


}

if keyboard_check_pressed(vk_space) && !place_free(x,y+1){

vspeed = -broo;


}
#endregion
1

There are 1 best solutions below

0
On

I think the !place_free(x,y+1) is the problem here

if keyboard_check_pressed(vk_space) && !place_free(x,y+1){
    vspeed = -broo;
}

Assuming place_free checks if there's no collision, it may either be a case of setting the origin point of the player object to the bottom center, or not having a solid instance or collision mask. (as seen in the manual)

I personally prefer using place_meeting to check on collisions with a specific object, and ignore the requirements needed for place_free to work, maybe that could work better for you.