r/gamemaker • • 11d ago

Help! help on gm2

i have been trying to make a platformer type game and i watched a tutorial on how to move the character and grav etc but it does not work at all, copied everything correctly and there is no comments on the post just wondering if anyone can help

#region movement
//key input
var _key_left = keyboard_check(vk_left);
var _key_right = keyboard_check(vk_right);
var _key_jump = keyboard_check(vk_space);

//calculate movement
var _move = _key_right - _key_left;
h_speed = _move * move_sp;
v_speed += grav;

//moving the player
if (_key_left){

}
//jumping
if place_meeting(x, y+1, Obj_wall){
jumps = jump_max;
}

if (jumps > 0) && (_key_jump){
jumps -= 1;
v_speed = jump_height;
}
#endregion

#region collision: horizontal, vertical
//horizontal
if (place_meeting(x + h_speed, y, Obj_wall)){
while (!place_meeting(x + sign(h_speed), y, Obj_wall)){
x += sign(h_speed)
}
h_speed = 0;
}
x += h_speed;

//vertical
if (place_meeting(x, y + v_speed, Obj_wall)){
while (!place_meeting(x , y + sign(h_speed), Obj_wall)){
y += sign(v_speed)
}
v_speed = 0;
}
y += v_speed;
#endregion
0 Upvotes

6 comments sorted by

1

u/germxxx 11d ago

"it does not work at all" Doesn't really help us narrow it down in any capacity.
You need to explain in detail what you've done and exactly what is happening, and what you expect to happen.

0

u/clanmckay 9d ago

the player pretty much doesnt move left to right and when you try to jump the player becomes attached to the blocks on top, all collisions work perfectly just the grav and movement that is not working

1

u/germxxx 9d ago

"Pretty much", So it does move a little?
Getting stuck is a common problem, usually caused by changes to the collision mask or wonky collision code.

Like in the vertical collision code, you have this:

while (!place_meeting(x , y + sign(h_speed), Obj_wall)){

But it should not be using h_speed in vertical collision.

But I also have to ask if the sprite changes at any point.
Because if it does, that could affect the collision mask, causing the player to get stuck.
That goes for anything using sprite_index, but also things like image_xscale.

So if you change the sprite at any point, you need to make sure that all sprites have the exact same collision mask and origin, OR, you can in the player object properties set the collision mask to a specific sprite, rather than the standard "Same as Sprite". If it's set to a specific sprite, it won't change as the sprite_index changes.

If you use image_xscale, make sure the collision mask i perfectly centered, so that it doesn't change when flipping the sprite horizontally, if that's something you do.

1

u/clanmckay 8d ago

sorry i phrased it wrong i just doesn’t move i am currently away and i will check when im back thanks for the help

1

u/clanmckay 8d ago

sorry i phrased it wrong i just doesn’t move i am currently away and i will check when im back thanks for the help

1

u/AmnesiA_sc 11d ago

If nothing at all is working, maybe it's not in the Step event or the object isn't in the room?