[Mkl]Those damn slopes!

Posted by Moikle on Feb. 17, 2012, 4:44 p.m.

Sup 64 digits, I am doing stuff.

I have finally decided to get off my arse and continue working on this project I have been stuck on for 2 weeks.

A while ago, back when I did a lot of GM stuff, I would have had this done in a day or two, but for the fact that I haven’t really done any engine stuff with it for a very long time, (only experiments and cool visual things), coupled with how my perfectionism level has raised significantly since then- meaning I will not accept any of the crappy solutions I may have come up with a year or more ago.

I am working on a platform engine which has pretty much all of the features I can see myself needing (although starting off with the basics of course). So far I have got the ability to play the game with either a keyboard or an xbox360 controller (and have also set it up so that adding local multiplayer should be easy) which is something I have never done in GM before, but I am rather happy with the result.

The problem however is slopes, the bane of every GMnoob (which I do not consider myself). I have created several platformer engines before that support slopes, but none that will support the current model.

I have got to a point where I do not understand where I have gone wrong, so here I am, asking for help on something quite simple.

Here is a link to the file, all of the problems are in the step event, highlighted…

//VVVVVVVVVVVVVVVVVVVVVVVVVVV

…like this

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is GM8.1 but I don’t know how to use LateralGM so sorry if you don’t have 8.1 :(

You can press enter to change control scheme

Keyboard:

Left/right arrows - move

X - jump

controller:

left stick - move

A - jump

Oh, and i just found another problem, the game starts off with extreme lag. this seems to fix itself if you attach a controller, and then disconnect it. even if you don't change the control scheme. I have no idea why…

Comments

JID 12 years, 10 months ago

I was about to download then I saw that the file was a .gm81

:(

Moikle 12 years, 10 months ago
JuurianChi 12 years, 10 months ago

:e

(I must fix my GM8.1's bugs.)

Cesque 12 years, 10 months ago

I won't be able to open it either, but here's how I solve slopes in my game (hsp=horizontal speed, negative or positive depending on the direction):

hsp_check=hsp
while hsp_check!=0
{
if !place_meeting(x+hsp_check,y,shade) {x+=hsp_check; hsp_check=0}
else if !place_meeting(x+hsp_check,y-4,shade) {x+=hsp_check; y-=4; hsp_check=0}
if hsp_check>0 {hsp_check-=1}
else if hsp_check<0 {hsp_check+=1}
hsp_check=round(hsp_check)
}

Basically, if there's enough space to go forward, go forward. If there isn't, try going forward and up. If you still can't do it, reduce the distance you're trying to go and repeat.

Oh yeah, I forgot to mention there's some "gravity" code applying afterwards, so that the player doesn't end up floating in the air (basically, lower his distance to touch the ground if it's close enough and he's not jumping, IIRC).

Rob 12 years, 10 months ago

Quote:
.gm81

Sorry man.

Quote:

Oh, and i just found another problem, the game starts off with extreme lag. this seems to fix itself if you attach a controller, and then disconnect it. even if you don't change the control scheme. I have no idea why…

I had this happen with a GM6.1 game too. Don't check for gamepad input unless there actually is a gamepad. Have some kind of usingGamePad boolean and only check for gamepad input when it's true (someone using a gamepad).

To mesh it better with your code you could make an input script I guess so for your movement code you'd just call if (Input(blah)) instead of if (keyboard_blah(blah) and joystick_blah(blah))

Moikle 12 years, 10 months ago

Quote:
Don't check for gamepad input unless there actually is a gamepad
I don't think I am.

It only checks if cscheme[0] = 1, and the game starts off with that as 0, only to be changed if the user presses enter (even then it checks once to see if there is a controller, and if there isn't, it jusst shows a message and stays as 0, and it changes it back to 0 if at any time the controller is disconnected while you are using it.)

Moikle 12 years, 10 months ago

Ah, i got LGM to work, uploading GMK version now, try the link again

Moikle 12 years, 10 months ago

Ok, for the climbing down slopes problem, I had forgotten to put abs(xspeed), but doing so still does nothing.

Ferret 12 years, 10 months ago

I'm totally proud of the current platformer I'm working on. If you have skype I'll talk with ya and give you some of my code ;D

(I just don't wanna share my stuff with the world quite yet.)

Rob 12 years, 10 months ago

Well, for one you're doing y + h instead of y - h. Although just changing that doesn't entirely fix it, but it helps.

and "move_contact_solid(270,abs(xspeed));" is bad. What if the player hits a ceiling? It'll teleport him down if that happens. Try 270 - 180 * (vspeed < 0) or something