SOLVED Problem in collision with the wall on platform

B

Bhreno

Guest
The obj_player has a pixel problem (-1) in collision with the wall, when it is on a platform that stops moving when it collides with this same wall. Even on the mobile platform, it must hit a wall when x + 1 or x-1 is a wall; however, it is stopping 1 pixel before and it is getting a vacant pixel between it and the wall.
The problem occurs when the obj_player is on a platform, and some x in front of it.
"colid 3": before the collision with wall (moving).
"colid 1": it worked.
"colid 2": did not work. This problem. The platform collides correctly, but the obj_player is 1 pixel away (sometimes, sometimes it hits).

CODE in STEP PLATFORM:
GML:
case oPlataGroundRight:
var wallCollision = place_meeting(x+(_hspd+1), y, oSolid);

if (wallCollision)
{
_hspd = 0;
}
else
{
_hspd = _moveSpeed;
};

if place_meeting(x,y-15,obj_player) && place_meeting(x,y-47,obj_player)
{
x += _hspd;
with(obj_player)
{
if(!place_meeting(x+(other._hspd),y,oSolid))
{
x+= other._hspd;
}}}
break;
 

Attachments

sp202

Member
You don't have code to move the player right against the wall in the case that there is a collision at the target position. You'll need to use a while loop to move it a pixel at a time until it's about to collide.
 
B

Bhreno

Guest
You don't have code to move the player right against the wall in the case that there is a collision at the target position. You'll need to use a while loop to move it a pixel at a time until it's about to collide.
And how would I do that? Could you give me a sense of the type of While code?
 

sp202

Member
GML:
if(!place_meeting(x+(other._hspd),y,oSolid))
{
    x+= other._hspd;
}
else
{
    while(!place_meeting(x+sign(other._hspd),y,oSolid))
    {
        x+= sign(other._hspd);
    }
}
 
B

Bhreno

Guest
GML:
if(!place_meeting(x+(other._hspd),y,oSolid))
{
    x+= other._hspd;
}
else
{
    while(!place_meeting(x+sign(other._hspd),y,oSolid))
    {
        x+= sign(other._hspd);
    }
}
It worked!!! Thank you!!
 
Top