Petrichor's platformer topic

I am working on a platformer game to play around with physics. Right now I just have collisions mostly working (they’re broken but fixing it is trivial) at https://c.gethopscotch.com/p/12xzzqnz24 and I intend to get characters and physics working soon.

I made this topic to have a single place to explain how I am thinking the project will work. To start that off, here is an explanation of how I am checking for collisions:

Each object has a position, size, and rotation. Each object is also a rectangle, though that is mostly for ease of coding and the collision system I use can be easily expanded to any size of convex polygon (I believe I have a slow but working implementation of this up to hexagons in https://c.gethopscotch.com/p/12ig8qg1up). Every time the object’s size or rotation changes, calculates where its vertices (corners) are relative to its center.
It then uses these corner offsets to determine the size of the smallest axis-aligned rectangle that covers it.
Each object that wants to allow other objects to check for collisions with it is then responsible for informing them about its location and size.
Each object that wants to check collision against something will somehow get this data and then will check for a collision by doing the following:

At this point that is as far as I have gotten, but after this is where I will use the collision result to push characters out of walls and floors.

15 Likes

cool topic! excited for the platformer!

5 Likes

not wanna deceive you or anything --in fact this is super super impressive-- but i quickly scrolled through your code and if all collidable objects on screen are running the collision code, im pretty sure your fps will start dropping considerably as you increase the number of polygons :( nonetheless, i give you the triangle (haha yes, a polygon, im too funny…) prize of creativity and mathematics :D

4 Likes

Not all collidable objects will be running it – only characters. Most objects will also be able to only use the aabb check – only collision pairs with at least one rotated object need the more expensive sat check. Any drop in fps caused by this under any use case that I can imagine except perhaps having a bunch of rope-type objects or something should be minimal.

One very important thing to keep in mind is to focus on optimization only when it becomes a problem. If it is not needed now it may not ever be needed. There is no sense in spending time on optimizations that may harm the ease with which you can code the rest of the project unless you absolutely need to. So if you’re just getting the first version of the draft coded don’t feel the need to focus on optimization. It can be very fun though when there are still massive performance gains for easy changes so I would definitely never recommend completely ignoring it.

7 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.