Separating Axis Theorem Collision

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheConfuZzledDude
Prole
Posts: 21
Joined: Fri Nov 02, 2012 10:23 pm

Separating Axis Theorem Collision

Post 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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Separating Axis Theorem Collision

Post by Ranguna259 »

Sorry for the late respons but I don't think SAT works with non-convex polygons.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
TheConfuZzledDude
Prole
Posts: 21
Joined: Fri Nov 02, 2012 10:23 pm

Re: Separating Axis Theorem Collision

Post 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...
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Separating Axis Theorem Collision

Post 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.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
TheConfuZzledDude
Prole
Posts: 21
Joined: Fri Nov 02, 2012 10:23 pm

Re: Separating Axis Theorem Collision

Post 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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Separating Axis Theorem Collision

Post 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 ? )
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests