
simple AABB collision problem
Hello all, I have an AABB collision issue...
I have numerous walls in a scene; they have been translated (but not rotated) to various places in the scene. This translation for each wall is saved, so I am able to use that for the world coordinate for collision detection.
The Camera/Player class I was trying to test using is pulling the position of it (x,y,z), and adding 1 unit to each to obtain the MAX box edges, and subtracting for the MIN bounding edges.
Currently, I''m only testing with 1 of the walls, so I can at least get part of it working initially.
The collision is a simple AABB collision detection:
if (playerMinX > wallMaxX) return false; //no collision
if (playerMaxX < wallMinX) return false; //no collision
if (playerMinY > wallMaxY) return false;
if (playerMaxY < wallMinY) return false;
if (playerMinZ > wallMaxZ) return false;
if (playerMaxZ < wallMaxZ) return false;
return true; //nothing returned false, so there''s a collision
This never registers a collision.
However, if after each of those IF''s, I put an "else return true;" statement, I get lots of false hits:
player(0,0,120)
wall (6.25,0,100)
collision @ playerMinX > wallMaxX
(which evaluates true...but not really a collision)
Probably the worst thing about this...I''ve done this before, had the same problem, don''t remember how it was fixed, and don''t have the code anymore either....
Help? =)

Shouldn't that last test be:
Enigma
EDIT: ugh that looked horrible
[edited by - Enigma on February 12, 2004 3:12:35 PM]
if (playerMaxZ < wallMinZ) return false
Enigma
EDIT: ugh that looked horrible
[edited by - Enigma on February 12, 2004 3:12:35 PM]
Yeah, it actually is MinZ... the code posted isn''t quite what my live code looks like, ''cause it''s sorta ugly as it is...
Here''s the live code (last line):
if ( (playerOneMaxZ) > (world.walls[wallNum].wallZ -wallCollideFactor) )
{ return false; }
The rest of the Min''s/Max''s for players and walls look pretty much like that.
Any other ideas?
Here''s the live code (last line):
if ( (playerOneMaxZ) > (world.walls[wallNum].wallZ -wallCollideFactor) )
{ return false; }
The rest of the Min''s/Max''s for players and walls look pretty much like that.
Any other ideas?
Post the real code. I can''t see anything wrong with the simplified version you posted.
Enigma
Enigma
Here''s the loop for the collision stuff...
The else''s are commented out, ''cause they give false collisions. As is, it gets no collisions. Let me know if you need more info...and thanks for the help.
for (int wallNum=0; wallNum<world.numberOfWalls; wallNum++) { if ( (playerOneMinX ) > (world.walls[wallNum].wallX +wallCollideFactor) ) { return false; }// else{ return true; } if ( (playerOneMaxX ) < (world.walls[wallNum].wallX -wallCollideFactor) ) { return false; }// else{ return true; } if ( (playerOneMinY ) > (world.walls[wallNum].wallY +wallCollideFactor)) { return false; }// else{ return true; } if ( (playerOneMaxY ) < (world.walls[wallNum].wallY -wallCollideFactor) ) { return false; }// else{ return true; } if ( (playerOneMinZ) < (world.walls[wallNum].wallZ +wallCollideFactor) ) { return false; }// else{ return true; } if ( (playerOneMaxZ) > (world.walls[wallNum].wallZ -wallCollideFactor) ) { return false; }// else{ return true; } } return true;
The else''s are commented out, ''cause they give false collisions. As is, it gets no collisions. Let me know if you need more info...and thanks for the help.

The last two tests are wrong. You have:
when you should have:
(Note the <''s and >''s).
Enigma
if ((playerOneMinZ) < (world.walls[wallNum].wallZ +wallCollideFactor)){ return false;}if ((playerOneMaxZ) > (world.walls[wallNum].wallZ -wallCollideFactor)){ return false;}
when you should have:
if ((playerOneMinZ) > (world.walls[wallNum].wallZ +wallCollideFactor)){ return false;}if ((playerOneMaxZ) < (world.walls[wallNum].wallZ -wallCollideFactor)){ return false;}
(Note the <''s and >''s).
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement