Legacy GM Slope collision, what's your method?

G

Geoff Moore

Guest
I want my character to be able to walk up and down slopes (platformer perspective). Do people generally use precise collision checking with a few different slope sprites or is there a better way? Thanks!
 
  • Like
Reactions: JAG

JAG

Member
:upvote:

I see lots of pre-gms2 tutorials out there, but Im curious how the new tile collision system could be used for slopes

edit: oops I see now this is tagged 1.4. In any case Im still interested.
 
Something like this from Shaun Spalding's youtube tutorials. I adapted it a little from my own project, so this is untested rn:
Create:
Code:
hsp=0;
vsp=0;
grav=.2;
Step:
Code:
//Get Inputs (However you want)
//if press right, hsp=2;, if press left, hsp =-2, etc...

//Apply gravity
if(vsp<10){
    vsp+=grav;
}

//Horizontal Collisions
if (place_meeting(x+hsp,y,oBlock)){
    //Up slope
    var yplus=0;
    while(place_meeting(x+hsp,y-yplus,oBlock)&&yplus<=abs(hsp)) yplus+=1; //change the abs(hsp) to 3*abs(hsp) if you want to be able to go up a 3-1 slope, etc..
    if(place_meeting(x+hsp,y-yplus,oBlock)){
        while(!place_meeting(x+sign(hsp),y,oBlock)) x += sign(hsp);
        hsp=0;
    }else{
        y-=yplus;
    }
}
x += hsp;

//Down slope
if !place_meeting(x,y,oBlock) && vsp >= 0 && place_meeting(x,y+2+abs(hsp),oBlock){
    while(!place_meeting(x,y+1,oBlock)) y += 1;
}

//Vertical Collisions
if (place_meeting(x,y+vsp,oBlock)){
    while(!place_meeting(x,y+sign(vsp),oBlock)) y += sign(vsp);
    vsp=0;
}
y+=vsp;
 

TheouAegis

Member
with tile Maps, you pick a point to look for a collisionat, find out which tile is at that point. then you get the deviation from the grid alignment that the point is at. Then you compare that deviation to some algorithm you have previously assigned to that particular tile type to fetch the y-coordinate that the tile is actually at.
 
Top