badwrong
Member
Project file: https://github.com/badwrongg/gms2stuff/raw/master/sloped_tile_polygon_collision.yyz
Edit2: Added capsule colliders. Probably the best option for platformers with smooth sloped movement.
Edit: Added rotation
I was curious about making a sloped collision system using tilemaps, since they are certainly faster than using objects.
So I came up with the solution of procedurally creating polygons for each tile shape an assigning a translated version of each
polygon to a grid that matches the tilemap.
Been working on it a few days now and here is the result so far:
It supports any convex ngon as a tileshape. And the collision mask of the object colliding with it has its own polygon assigned as well.
That assigned polygon can also be any ngon too, so like a pentagon or hexagon collision mask for the player would work if that's your thing lol.
Anyway, its almost done. I'm still fiddling with how the collision response works. But the core solution is solid and performs very fast.
When I saw how other tile based slope collisions are done I saw that they usually avoid using math at the cost of performance. So this
solution instead uses some good old math in order to not sacrifice performance.
The tile collision check is still just like the standard tile collision check, but then it resolves the collision differently. Currently it has two methods that
can be switched between. One is the separate axis theorem, which is fairly common I think. The other is diagonals of each polygon against edges of the other,
and then vice versa. Still fiddling with which one I prefer I guess.
Edit2: Added capsule colliders. Probably the best option for platformers with smooth sloped movement.
Edit: Added rotation
I was curious about making a sloped collision system using tilemaps, since they are certainly faster than using objects.
So I came up with the solution of procedurally creating polygons for each tile shape an assigning a translated version of each
polygon to a grid that matches the tilemap.
Been working on it a few days now and here is the result so far:
It supports any convex ngon as a tileshape. And the collision mask of the object colliding with it has its own polygon assigned as well.
That assigned polygon can also be any ngon too, so like a pentagon or hexagon collision mask for the player would work if that's your thing lol.
Anyway, its almost done. I'm still fiddling with how the collision response works. But the core solution is solid and performs very fast.
When I saw how other tile based slope collisions are done I saw that they usually avoid using math at the cost of performance. So this
solution instead uses some good old math in order to not sacrifice performance.
The tile collision check is still just like the standard tile collision check, but then it resolves the collision differently. Currently it has two methods that
can be switched between. One is the separate axis theorem, which is fairly common I think. The other is diagonals of each polygon against edges of the other,
and then vice versa. Still fiddling with which one I prefer I guess.
Last edited: