Something’s askew here…

A week ago, I had a bug-free, perfectly-good platforming engine. But then out of a whim, I decided to mess around with it and added support for sloped platforms.

Aside from a few bugs with the player or enemies occassionally getting caught in the slopes, it seems to be working just fine:

Implementing the code to make objects moving up slopes was the easy part. However, in the method I’m using, it initially caused objects to “float” above the slope, with only one corner touching it tangentially.

This looks particularly bad if the sprite is wide, (which kitty is in my case).

The first solution to this problem I considered was to make the object’s collision mask narrower than the actual sprite. However in my case, this would have caused another problem: kitty would have been able to walk partially through thin walls, which would have messed with the gameplay.

The solution I ended up using was to give the object two collision masks: a narrow one (coloured orange in the image below) for detecting the contour of the ground (and ceiling) and a wider one (blue) for detecting walls and everything else.

Now some of the “floatiness” has been transformed into “phase-through-the-ground-ness”, which I think is more tolerable. Both become less noticeable when the slope grade is reduced:

Foreground scenery (red) can be used to hide the remaining floatiness. In “Cat Project”, the fuzziness of the carpet platforms does this somewhat.

A challenge with implementing this within GameMaker:Studio is that it only checks for collisions automatically in each step once, with only one collision mask, and fires off Collision events accordingly. After doing a bit of searching on the Game Maker Community forums, I found that a way to get around this one-mask limit is to cycle through a list of masks, manually recheck for collisions between each mask change and execute the appropriate code for each. Essentially, you’re implement additional Collision events inside another event (usually a Step event).

Leave a Reply

%d bloggers like this: