Page 1 of 1

Separating Axis Theorem Collision

Posted: Thu Jan 02, 2014 12:31 am
by TheConfuZzledDude
I'm trying to use SAT for the collisions in my game. So far, the actual collision detection with rectangles is working fine, but detection with non rectangular polygons is really weird and the translation of polygons out from other polygons is also weird. Any help with this?

https://dl.dropboxusercontent.com/u/300 ... ision.love

Re: Separating Axis Theorem Collision

Posted: Sat Jan 04, 2014 5:01 pm
by Ranguna259
Sorry for the late respons but I don't think SAT works with non-convex polygons.

Re: Separating Axis Theorem Collision

Posted: Sun Jan 05, 2014 3:58 pm
by TheConfuZzledDude
Ranguna259 wrote:Sorry for the late respons but I don't think SAT works with non-convex polygons.
Yeah I know.That's why my polygons are all convex...

Re: Separating Axis Theorem Collision

Posted: Sun Jan 05, 2014 5:25 pm
by Ranguna259
I'm sorry I can't be of much help but using SAT or any other method for collision detection will just make your code buggy, your best bet is to use LÖVE's physics module but if you really want to make your own collision detection code then I wish you the best of luck.

I've tried coding my own collision detection code but they never, NEVER worked, I almost went crazy over it until I tried love.physics.

Re: Separating Axis Theorem Collision

Posted: Sun Jan 05, 2014 8:02 pm
by TheConfuZzledDude
The thing is, the actual collision detection works (at least for rectangles) but it's just the moving of one polygon out of the other that's the problem

Re: Separating Axis Theorem Collision

Posted: Sun Jan 05, 2014 8:46 pm
by Ranguna259
Actually your collision detection isn't so good (and it isn't your fault, it's SAT's)
1. When a rectangle is colliding with another it kind of "trembls", because you are drawing the rectangles before (and maybe after) the collision code (I'm guessing) and the rectagles should only be drawn after the the code detects collision:
-- Movemente code
-- Collision detection code
-- Draw code

2. Whenever a rectangle is colliding into one of the upper/bottom sides of another rectangle the moving rectangle is teleported to one of the vertical sides(the left or the right side), and this is a SAT problem, SAT has this paticular problem that it can't detect from and where the moving rectangle is going and that creates teleportation glitches.

I remeber reading in Mari0's collision detection code, Maurice used the AABB method (Axis Aligned Bounding Box), and it worked quite well, but not well enough, even AABB has teleportation glitches and has some problem with diagonal (vertice to vertice) collision, here are two comments in Mari0's collision detection code:

Code: Select all

--We're fucked, it's a diagonal collision! run!
--Okay actually let's take this slow okay. Let's just see if we're moving faster horizontally than vertically, aight?
(What do you mean moving one polygon out of another ? )