3D bounding box just not working

im trying to detect a collision between two cubes and it just doesn’t seem to work


public class collision {
	public static boolean cubeCollision(cube c1,cube c2){
		return ((c1.x < c2.x+c2.w) && (c1.x+c1.w > c2.x) && 
				(c1.z < c2.z+c2.d) && (c1.z+c1.d > c2.z) && 
				(c1.y < c2.y+c2.h) && (c1.y+c1.h > c2.y));
	}
}

[s]EDIT:

I got this working now, the issue was that i wanst drawing the box the same way as i was detecting collision[/s]

EDIT:

No it’s still not working, the box detects collision when you are above it not inside of it. The x and z axis are fine but the y axis just doesnt wanna work :L

Just adding this reply to put this back at the top of the section of the forums :stuck_out_tongue:

hehem…

I’m pretty sure this helps :slight_smile:

EDIT:


public static boolean testAABBAABB(final AABB box1, final AABB box2) {
   if (Math.abs(box1.center.x - box2.center.x) > (box1.r[0] + box2.r[0])) return false;
   if (Math.abs(box1.center.y - box2.center.y) > (box1.r[1] + box2.r[1])) return false;
   if (Math.abs(box1.center.z - box2.center.z) > (box1.r[2] + box2.r[2])) return false;
   return true;
}

collision still seems to be off, it feels like the collision detection for the cube has been pushed away from the box a bit

EDIT:

just seems to be the y axis thats off :L