• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker {SOLVED} Coding slopes - Electric Boogaloo: predict and adjust my Y position while walking on slopes

R

Rednavi

Guest
So after working for a while on this I finally managed to almost complete the slope support coding for my platformer action game. The last thing left to finish now is a method to adjust my Y position while walking on the slope (Y position is set correctly while LANDING on it so that's fine). Basically this is what I need help with:

000.png 001.png 002.png 003.png

If you're walking on common ground and eventually walk off of it the character will change his state to the falling state as desired, as there's no ground below him. A variable is set to prevent this if you walk on slopes. That way I can freely walk left and right without triggering a falling state while on a slope (And no slopes have a dead end, they always link to common ground). So accidentally falling while walking downhill is not an issue. Now here's the deal:

* I need something that lets me do this through Y position manipulation (So no vertical speed changing. The vsp should stay the same).

* My position when on a slope should always be (position_meeting_rounded(x,y+1,par_slope) so I need a way to enforce this while on a slope. Both when I'm going to be inside of a slope (walking towards an upwards hill) and when I'm walking downhill (Which so far ends up with me on the air).

* I've reserved a variable for when I'm on a slope (aptly named onslope) so this wont conflict with anything else (Like say, trigger a falling state for example. That wont happen).

* If my position does not equal to that, then I need to increase or decrease my y position accordingly in one single frame. All through y position tweaking.

* This has to work while I'm moving on the slope as I've already taken care of setting my y position correctly when walking into a "slope buffer" from common ground and while landing on any spot of any slope. All that's left to solve is the y position while moving ON the slope itself.

* Slope detection uses position_meeting because all I care about whether my character's axis is in x,y+1,par_slope or not, as shown in the pictures. The rest of the bounding box is irrelevant for this. So avoid the use of place_meeting for this.

* Slopes have their collision set to precise and there are 3 basic slope types: The 45 degrees one shown in the pics and two others with 1/2 and 1/4 of that slope's height.


I believe nothing else is really needed right? Let me know if you need any piece of coding for this.
 
R

Rednavi

Guest
I solved it I guess. I ended up writing this inside of my collision checking script:

// If inside the slope then go up until hitting the surface
if grounded=1&&onslope=1
while (position_meeting_rounded(x,y,par_slope))
{y--}

// If walking above slope but not on surface then go down
if grounded=1&&onslope=1
while (!position_meeting_rounded(x,y+1,par_slope))
&&(!position_meeting_rounded(x,y,par_slope))
{y++}

I hope this wont come back and bite my ass later on causing glitches or something. So far so good, I just had to tweak some extra coding to make sure that the grounded and onslope variables are set up ASAP.
 
Top