Pixel perfect collision?

How do I…

I have 2 sprites, and i want to check for a collision between them. One is my collision map (just a version of my map but for collisions so it has no detail just solid) and my player. I dont want to use collision masks, i tried and it just kept saying “polygon is not convex” and i would lose alot of time trying to get it to work. Is there a way to get pixel perfect collision based on a sprite?.

What is the expected result

The player stops when touching the collision map

What is the actual result

The collision does not work because it is not convex.


Short answer: No, not in the way you’re looking to do it.

For more detail: (Nearly) every advanced game engine requires you to map out your polygons. Almost no game engines support concave (non-convex) polygons for collisions, and the few that do strongly recommend against it.

If you absolutely must have a concave shape, what you can instead do is make multiple collision masks (on the same object) out of convex shapes.


As an example, the convex shape above will work fine. To make the Concave shape, you’ll need two polygons in your collision mask, both concave, that align on the side with the indent.

Basically, you’d split the concave shape along the line below by making two convex polygons.

Edit: Basically, concave isn’t supported by most physics engines due to how mathematically taxing it is vs convex shapes. Reddit - Dive into anything

1 Like