Player getting stuck on sides of wall

C

CitrusGaming

Guest
so im trying to make a game where you are a ball and you can move around by turning the camera, and the gravity direction is what moves you, but whenever you hit a diffrent side of the floor the player gets stuck, please help.

Step event Player:
Code:
hsp = hsp + grv;
vsp = vsp + grv;

if (place_meeting(x+hsp,y,Floor))
{
    while (!place_meeting(x+sign(hsp),y,Floor))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}
    x = x + hsp;


if (place_meeting(x,y+vsp,Floor))
{
    while (!place_meeting(x,y+sign(vsp),Floor))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
    y = y + vsp;
    
    
    if (place_meeting(x-hsp,y,Floor))
{
    while (!place_meeting(x-sign(hsp),y,Floor))
    {
        x = x - sign(hsp);
    }
    hsp = 0;
}


if (place_meeting(x,y-vsp,Floor))
{
    while (!place_meeting(x,y-sign(vsp),Floor))
    {
        y = y - sign(vsp);
    }
    vsp = 0;
}
Create event Player:
Code:
hsp = 0;
vsp = 0;
grv = gravity;
walksp  = 0;
gravity = 0.3
collision floor even Player:
Code:
if( vspeed > 0){
    vspeed = 0;
}

if( vspeed > 0){
    vspeed = 0;
}
key down right:
Code:
Camera.a -= 2
gravity_direction += 2
key down left:
Code:
Camera.a += 2
gravity_direction -=2
 

FrostyCat

Redemption Seeker
First, get rid of duplicate blocks of code starting with if (place_meeting(x-hsp,y,Floor)) and if (place_meeting(x,y-vsp,Floor))
. The sign of hsp and vsp already takes care of movement in the positive and negative directions, handling it twice is clearly asking for trouble.

Second, get rid of all code referencing gravity, and use grv only. You don't want both the built-in mechanism AND the manual mechanism affecting movement at the same time. If you want to change the manual gravity's direction, use another variable.
Code:
grv = 0.3;
grv_dir = 0;
Code:
hsp = hsp + lengthdir_x(grv, grv_dir);
vsp = vsp + lengthdir_y(grv, grv_dir);
 
Top