I'll post it here since it's a game maker thread, I have a problem, and I think I'm going nuts, I'm very close to pulling off my hair.
This shit is so simple, and I have done it before but it just doesn't want to work properly now, no matter what I do. It's about platforming collisions, and I think I tried to fix this for 3 days now, I'm going mad that I cannot pass such a simple problem. Here's the thing, my character occasionally gets stuck horizontally, he is moving into an object vertically probably and the game sees him as not able to move. I checked over ten times that my sprite origins, and masks, all of them, even the size of the sprites are the same. They are even centered so it won't switch the hitbox into an object suddenly. This bug mostly happens when the character moves down objects that are 8 pixels away from each other vertically, and near each other horizontally.
//HORIZONTAL collision
//if we will collide at our right/left with the ground, move us right near the ground horizontally and stop
if (place_meeting(x + hspeed, y, obj_ground))
{
//until we are close keep moving 1 to left/right
while (!place_meeting(x + sign(hspeed), y, obj_ground))
{
x += sign(hspeed);
}
hspeed = 0; //then stop the hspeed
}
//VERTICAL collision, if we are in air do this:
if (!place_meeting(x, y + 1, obj_ground))
{
gravity = PlayerGravity;
grounded = false;
}
//If we meet solid at position + vertical speed (this should do nothing when we just stand)
if (place_meeting(x, y + vspeed, obj_ground))
{
//if we aren't grounded move down by 1
while (!place_meeting(x, y + sign(vspeed), obj_ground))
{
y += sign(vspeed);
}
//stop his speed to not accidentally move him into an object
gravity = 0;
vspeed = 0;
//if we moved on top of an object then we are grounded, else we are descending
if (place_meeting(x, y + 1, obj_ground))
{
grounded = true;
if (StateId == state_jump)
{
StateId = state_idle;
}
}
}
Of course I have another script which changes his vspeed to jump if you press the jump key, and another one which moves him left or right if you press direction keys. And in that script, it won't let you move left or right if you will collide with something horizontally. If you will collide with something, it will move you close to the object.
I just don't understand, I am literally going crazy over this because I can't start moving on the game because of this stupid shit bug. It only occurs if you place platforms close to each other, and elevate each one of them lower. You will sometimes get stuck to them, just fucking kill me already.