• 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!

SOLVED Player hits a Wall object from below and pummels down, getting stuck

Hi. I've been trying to find out why this happens.
I'm starting a basic platformer game as practice. So far I have two objects with their respective sprites (both with their origin in the middle centre): an oPlayer and oWall. I've mostly followed Shaun Spalding's tutorials on platformer movement, so the code below is basically the same as the one in the videos.

Everything seems to work as it should, except when my player jumps and collides with a wall from below. The player instantly pummels down and proceeds to "get stuck" wherever it collides. I can't move horizontally and can only jump again, so, the only way to get them out is by jumping again and moving mid-air to land somewhere else where they won't collide with a wall object from below. This is obviously very annoying.

I've tried to search different tutorials in platformer movement as well as all the others from Shaun, and from what I've gathered I could either use the built-in GMS physics or try more advanced code. However I want to understand why this vertical collision error happens, and if there is anyway I could fix it without having to change my code or its structure. Thanks!

(Edit1: the following code is from oPlayer)
Create Event:
GML:
//Creates these instance variables once oPlayer spawns
hsp = 0; // horizontal speed
vsp = 0; // vertical speed
grv = 0.2; // gravity
jumpsp_1 = 7; // jump speed
walksp = 4; // walk speed
Step Event:
GML:
//Input Check
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check(vk_space);

//Calculate movement
var move = key_right - key_left;

hsp = move * walksp;
vsp += grv;

//Jump Mechanic
if (place_meeting(x, y + 1, oWall))
{
    vsp = key_jump * -jumpsp_1;
}

//Horizontal Collision
if (place_meeting(x + hsp, y, oWall))
{
    while (!place_meeting(x + sign(hsp), y, oWall))
        {
            x += sign(hsp);
        }
    hsp = 0
}

x += hsp;

//Vertical Collision
if (place_meeting(x, y + vsp, oWall))
{
    while(!place_meeting(x, y + sign(vsp), oWall))
        {
            y += sign(y);
        }
    vsp = 0;
}

y += vsp;
Edit2: turns out I choked a little when writing the vertical collision part. Inside the while it should be y += sign(vsp) instead of y += sign(y)
 
Last edited:
Top