Discussion on Slopes and Collisions

Continuing the discussion from General Project Updates Topic 2:

Oh I believe you, slopes are pain lol.


Oh my gosh, we have functional Platformer slopes now
Just gotta make the other one and we can have Super Mario Maker 2 in Hopscotch. /j


We always had functional slopes. Just ask Spy Guy 96 and Awesome_E. Some of us just never use them because they can make the game lag a lot if not optimized.

I bet Spy Guy 96 is about to prove me wrong, lol…


I know
Just did it for the joke :stuck_out_tongue:


Eventually, I will try to get it as optimized as possible (and try to make it compatible with Local Collision, but that’s a whole different project). If I do get it perfect, I’ll genuinely be surprised…


That’s not actually the reason for me! And using local collision makes collisions basically not lag (compared to regular collisions at least lol)

Slopes were intended to be Raccoon with a Broom, but they were unstable. They worked in isolation but couldn’t work with other tiles. Currently, there are 2 problems with slopes that I can’t fix.

  1. If a slope leads into a ceiling, the slope will try to push the player into the ceiling while the ceiling tries to push the player into the slope, leading to all sorts of collisions bugs. Something similar happens when a slope leads into a floor

  2. If you have a solid tile with a slope above and to the side of the tile, the solid tile will still interact with the player even though it’s not supposed to. This can cause the player to bump into a wall while going up a slope.

I actually got slopes to work somewhat stable 5 years ago with some bugs, but that project used an entirely different collision technique so I’m not sure if that would work today. Also I’m not sure if that project fixed issue 1 lol.


You can check, but I can guarantee it didn’t…


Ceilings? No.

Floors? Surprisingly yes!


actually, i might gonna work on slopes this weekend. not promises tho- xD



If the player is the same height as the tiles (which is usually never the case), then you might be able to add an extra collision collision check to check the collision of the tile directly above another.

i.e., if the tile is a slope and the tile above is solid, then it’ll treat the slope as solid (but only if the player is the same size as the tile) it’ll treat the slope as solid, otherwise it treats it like normal.

Speaking of, the max distance a player can go up the slope before hitting the ceiling above happens to be equal to max(\text{tile_height} - \text{player_height})(0), going from the base of the slope up.


What if there is a collision collision collision?


…and that’s why I call mine Tile Collision Check


After some thought, I have come to the conclusion that you’ll need to reference the collisions above and adjacent to the slope (the tile above is for cases where the slope goes into a ceiling, and the adjacent tile is for cases where there’s a small gap where the player may not quite fit. The tile directly above the slope will always take priority).

Of course, it’ll look like it’s floating if the player happens to be a rounded square.

@Spy_Guy_96 I’m curious. What kind of glitch did you experience regarding the floors with your slope test(s)?


imo, instead of pushing a player to the top if they are inside an object, they should push you diagonally so that over frames, youre getting unstuck. but i havent worked on slopes yet so idk xD


Another common problem with slopes is that the player might detect the collision of the tile below the slope, which might force your player to snap to the beginning of the incline… In most cases, it’s easier to make slopes in Scratch because you can take tiny steps to ensure it always lands on top of the slope.


I had an issue where the player gets pushed into the ground because that’s where the slope was going.


That’s what I means to say when I was talking about the 2nd problem with slopes haha.


yea no promise at all but ive been working on a polygon bounce collision thats not local :eyes:

squares, rectangles, triangles, circles, stars, etc :eyes:


Local collision? I’ve been hypothesizing a collision method in which only the eight tiles that could potentially be interacting with the player will check whether the player is inside bounds to interact with them, but that would only work in grid-based scenarios. How does local collision work?


The way local collisions works is, you have a string of characters that represents the collision data of a level, and the code has to figure out how to use this string to do collisions.

So let’s say that we have a level that is 4*4 tiles big. The collision data string may look like this:


In this example:

b = solid tile

a = empty tile (air).

This of course doesn’t look like anything, unless we visualise the string differently!

Using our knowledge that the level is 4*4 tiles, we can visualise the string like this and you can start seeing how local collisions work:





We take every 4 characters of the string and put it on a new line. As you can see, this collision data represents a box where b is solid and a is air.

Note: the game still uses the regular string for collisions, this is just a visualisation.

So whenever the game wants to perform a collision check, it checks all the tiles that are around the player.

In my games at least, I restrict the size of my characters to minimise collision checks so only 4 checks have to be done. But yes it is possible to have bigger characters, you just need exponentially more collision checks.

Anyway, it does this by taking the players position and dividing it by the distance between the tiles (usually 64), and then floor() the result. We now have the position of the tile that’s to the lower left side of the player.

Then (assuming the collision data string goes from left to right from down to up), we can figure out what tiles exists at that position using this formula:

TileX + (TileY * LevelWidth).

After that we do collision like normal.

Do this 3 more times with the other tiles around the player and you’ve successfully done local collisions!