Game Maker Studio 2 Platform Engine Part 11

Subscribers:
180
Published on ● Video Link: https://www.youtube.com/watch?v=B5Zv_XfK9lQ



Duration: 0:54
184 views
3


Sorry for the long wait between updates, OBS's window capture stopped working for me for some reason so I couldn't record and thus upload anything.
I totally rewrote the code from scratch, let me explain what's going on in it:

1. A spatial hashmap has been added. Game Maker's default collisions loop through every object in the room, which A. is CPU costly, and B. is why you should avoid using objects for platforms unless they're moving platforms. A spatial hashmap is basically a grid with large cells that spans the whole room. Every object sorts themselves into these cells. When an object has to check for collisions, the object only needs to check objects that are in the same grid cells. This is, as you can imagine, an absolutely massive boost to the framerate, especially when you have a lot of objects and they're spread out across the whole room. It was a total pain to set up since I needed to set up a ds_list for each cell of the grid but surprisingly it doesn't seem to cost much more memory.

2. Vector platforms have been added. I've attempted this before in GMS1 and I even have videos up of that, but back then I took a misguided approach and used costly line intersection checks which lowered the framerate to about 200-300fps. As you can see by the constantly updating number in the upper left corner, the fps is a lot higher than that now! Turns out you just need to get the slope of the vector’s line (y2-y1) / (x2-X1) and then solve for y = mx + b, with x being your x (yeah, didn’t expect the algebra you learned in middle school to be important again, did you?).