Handling angled collision boxes

,

To create collision detection that not AABB, do I need to create an AABB big enough to cover it all and then test for transparent sprites?

image

Sounds like a pretty good idea to me.

1 Like

You can do it that way, but it will be very slow.

Collision detection is just math basically. The CPU is very fast when calculating pure math.
Testing for transparent sprites involves reading from memory (alpha values of the textures). Accessing memory is at least an order of magnitude slower than just doing math.
I would guess you will only manage checking a handful of objects while maintaining 30fps+ (while also drawing and calculating your general game logic).

Now you have multiple ways around this:

My library is a C implementation of a collision checking algorithm called Separating Axis Theorem (SAT). There is also a Lua version in the repository, which might be "good enough", if you only have a couple of entities.
I have not gotten around to writing much documentation, but the repository contains an example project, which you can copy to get started and see how the library is used. The library currently only supports circles and polygons (so you have to model the rectangles as polygons).

If you end up trying it out and have any troubles, feel free to ask.

1 Like

I didn't know about polygon intersection. That might be what I need.
I'll have a play. Thanks.