IgnacioG
Member
Hi everyone, I need help with a somehow specific problem.
I'm working in a 2D pixel platformer and obviously one of the first things that I implemented was collisions with platforms. To be honest collisions aren't my forte so when I found this problem I ignore it at first but is been a couple of months and now I need a solution for it.
This problem is that the player get stuck in solid platforms when he falls to close to the edge, this can happen in two situations:
Jumping and falling above the platform very close to it's edge.
Going to the edge of the platform, running to one side to fall and running to the other side as soon as you start falling. This method was used for the pictures below (The red square draws the collision mask of the player).
When the player get stucked you can't move horizontally and sometimes you can jump out of it depending on how deep into the platform is the player, but you have to move horizontally in the air after jumping or you get stucked again.
This is the code for collisions
other important stuff about the game:
I'm working with small sprites and because of that the camera's proportions are 426x240
vSPD and hSPD are rounded because gravity and acceleration works with decimals. If I don't round this values the player's sprite starts to have a wave-like movement if there's a change is it's position.
This also happens with one way platforms, but the player just falls form it all together.
Any sort of help would be appreciated
I'm working in a 2D pixel platformer and obviously one of the first things that I implemented was collisions with platforms. To be honest collisions aren't my forte so when I found this problem I ignore it at first but is been a couple of months and now I need a solution for it.
This problem is that the player get stuck in solid platforms when he falls to close to the edge, this can happen in two situations:
Jumping and falling above the platform very close to it's edge.
Going to the edge of the platform, running to one side to fall and running to the other side as soon as you start falling. This method was used for the pictures below (The red square draws the collision mask of the player).
When the player get stucked you can't move horizontally and sometimes you can jump out of it depending on how deep into the platform is the player, but you have to move horizontally in the air after jumping or you get stucked again.
This is the code for collisions
GML:
#region Horizontal Collision
if(round(hSPD) != 0)
{
if(place_meeting(x+round(hSPD),y,obj_solid))
{
repeat(abs(round(hSPD)))
{
if(!place_meeting(x+sign(hSPD),y,obj_solid))
{
x += sign(hSPD);
}
else
{
break;
}
}
hSPD = 0;
}
}
x += round(hSPD);
#endregion
#region Vertical Collision
if(round(vSPD) != 0)
{
if(place_meeting(x,y+round(vSPD),obj_solid))
{
repeat(abs(round(vSPD)))
{
if(!place_meeting(x,y+sign(vSPD),obj_solid))
{
y += sign(vSPD);
}
else
{
break;
}
}
vSPD = 0;
}
}
y += round(vSPD);
#endregion
other important stuff about the game:
I'm working with small sprites and because of that the camera's proportions are 426x240
vSPD and hSPD are rounded because gravity and acceleration works with decimals. If I don't round this values the player's sprite starts to have a wave-like movement if there's a change is it's position.
This also happens with one way platforms, but the player just falls form it all together.
Any sort of help would be appreciated