[SOLVED] getting stuck while walking on slopes

HaloElite

Member
I'm using this part of code to walk up slopes:

Code:
if(keyboard_check(vk_left)){
    hsp = -4;
}else if(keyboard_check(vk_right)){
    hsp = 4;
}else {
    hsp = 0;
}

// Slow down opposite x-movement when jumping
if(sign(hsp) == 1 && moveL || sign(hsp) == -1 && moveR) hsp /= 2;
if(sliding == true) hsp *= 2;

// When hitting a slope
if(place_meeting(x + hsp, y, solids)){
  
    yplus = 0;
    // Checks height of slope
    while(place_meeting(x+hsp, y-yplus, solids) && yplus <= abs(1*hsp)) yplus += 1;
  
    // Walks
    if(place_meeting(x+hsp, y-yplus, solids)){
        // Walks x-wise
        while(!place_meeting(x+sign(hsp), y, solids)) x += sign(hsp);
        hsp = 0;
    }else{
        // Walks y-wise
        y -= yplus;
    }
}
x + hsp;
It works fine but when I'm changing the direction while TOUCHING the slope the player is getting stuck and can't move in the changed direction.
e.g: While touching the slope and walking to the right and pressing vk_left and then vk_right again it's stuck instead of walking.

The error just occurs when changing direction like: walking right - changing to left - trying to walk right again - stuck.

Best regards,
me
 

HaloElite

Member
Okay, I solved it by adding just a little line to the beginning of the code:

Code:
if(place_meeting(x, y + 1, solids)) y -= 1;
 

Raff

Member
Hello,

Don't know if it will fix the problem but it's better to move first in the x axis and then move in the y axis. Specially with slopes, i think.
 
Top