I’ve been doing some research on how 2d collision can be carried out on Roblox. It’s not as straight forward as it is on other game engines like Unity where you simply add the Collision component (ex: Polygon Collider) and a collision box takes the shape of your sprite image.
I’ve gone briefly through several threads & videos but I haven’t come across an example where irregular Polygons are used. Only seen quadrilaterals and circles. Might sound obvious but I also noticed that different polygons have different collision validation code.
Am I right in concluding that I would have to come up with different algorithms and ways to validate collisions for different sprite images? Although, I have no idea how to this because when you load an image in an ImageLabel, the shape’s still basically a rectangle.
I am not really creating anything specific, I am just experimenting around because I was curious how 2d works on Roblox and why I don’t see any platformer games.
I also would be up for the challenge of trying to come up with some sort of algorithm, however I just don’t see how I would be able to access the actual Sprite Image shape from an image label. Maybe a way to detect pixels but I am not sure tbh.
Since you’re trying to make a 2d game on a 3d engine, It seems way easier and less time consuming to force the player’s perspective to make it look like a 2d environment. This way, you can still utilize roblox’s physics system since you’d still be using 3d colliders, and if you want to use sprites, you can just put them as decals over the colliders.
The one thing you’ll find with collision detection in general is that it’s only really viable for convex polygons.
Most games tend to split higher-detailed concave polygons down into smaller convex ones. They also tend to do collision in phases for optimization purposes (e.g. a broad phase w/ octrees, then a medium phase AABB, then a detailed phase convex decomp check).
In order to have a full blown 2D game w/ lots of collisions you’ll need to take these things into account.
I don’t know if anyone has attemped doing this on Roblox, but I think it probably wouldn’t run that great. The 2D elements of the Roblox engine have recieved nowhere near as much love as the 3D ones.
I think @Homemade_Meal has the right idea. If you’re going to be making a full blown 2D game you’re better off taking advantage of the 3D engine and translating that into the 2D space.
Omg it’s the goat himself
I swear I’ve prolly gone through 100s of tutorials made by you throughout my scripting time.
Thank you so much for your contribution to the community.
I understand and yes, I agree, it does make more sense to use 3D features to spice it up a bit. There are so many limits to it and they should really give the 2D space some love.
I did some testing with SpriteSheets and SurfaceMaps and got good results. I was gonna do a tutorial on it after I figured out some other stuff. SpriteTesting.rbxm (10.5 KB)
A few years back, my comp sci teacher made us a 2D trianglulator thing that took an image and let you draw a boundary for a hitbox. It would then calculate an assortment of triangles based on the vertex points of your selection for the boundary. We were using a 2D physics engine called Box2D (in c++) so we could create an assembly of triangles to be considered as one collision object, but have collision checks for all the triangles.
I imagine you may have to do something like that to get accurate collisions using guis.