0
\$\begingroup\$

I have been trying to get my slopes to function for almost a month now, doing nothing else with the project. Rewrote it 6-7 times in different collision styles, sometimes coming close to success while still being stuck with absolutely no help I could find during this month.

Here are the methods that I tried and what happened:

First I followed a video tutorial specific to game maker 2's tile collisions. It fills an array with how many pixels are filled on the y axis for every pixel on the x. Then it calculates how deep the player's (bounding box) bottom-center is in the slope tile and pushes him above the corresponding pixel count from the array.

Worked great for my floor slopes, didn't for my ceiling slopes. So I tried to reverse the way the pixels are counted and got a proper array, however fiddling with this system for 2 weeks alone, I still got stuck, presumably due to a math error.

If you are interested about this system, I basically posted everything there is to it on the yoyogames forums: Here

I definitely need ceiling slopes to work, since the game is a Metroidvania like game, where there might be a lot more vertical movement going on.

But then I figured, I could simplify this whole procedure, since my pixel art aesthetic currently uses one type of slope (where I potentially would like to keep the system to work with any slope that is a straight line for future additions) Currently my only slope is 2 tiles wide and 1 tile high.

I tried around with setting the player's y coordinate according to the linear function y = m*x + b I tested this by putting in y = -0.5 * current player position + the y coordinate of the slope tile in the room. However this function sets my player a fair bit above the slope, in the air. I know this is a lot to ask and maybe I'm totally stupid about this problem but I really tried HARD on this one, with my current knowledge and the one that is readily available I can't solve my issue.

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Turns out the answer was indeed calculating it with y = m*x + b Which means for game maker studio: Get the slope tiles x and y coord = x/y & ~ TILE_SIZE_MINUS_ONE make a switch case for your slope detection (I made them not detectable for my other tile collision so tilemap_get_at_pixel returns 0 for air, 1 for full solid blocks and anything from 2-9 for the slopes) then populate the formula, which differs a bit from slope to slope. My bottom floor right slope made it so the formula was: y = -1 * (x - Tile_x) + TILE_SIZE + Tile_Y - 1 - sprite_bbox_bottom;

Since Tile X and Tile Y are the top left corner of the cell I need to add (remember, this means go down in GMS and many other engines) the Tile Size to get to the origin point where x = 0 (where the slope starts, basically). - 1 to stand above the tile by 1 pixel and - this bbox variable, which was calculated to be the distance between the bounding box and the origin of the sprite (center).

Sad that nobody could help me with this but hey, now I know. Thanks for reading.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .