# Why is my AABB vs AABB code returning false positives

I am trying to do AABB vs AABB collision and the code is never finding a collision.

    private static boolean checkFullCollision(Entity entity, Entity entity1) {
float[] amin = entity.getMin();
float[] amax = entity.getMax();

float[] bmin = entity1.getMin();
float[] bmax = entity1.getMax();
return  (amin[0] <= bmax[0] && amax[0] >= bmin[0]) &&
(amin[1] <= bmax[1] && amax[1] >= bmin[1]) &&
(amin[2] <= bmax[2] && amax[2] >= bmin[2]);
}


where I calculate my min and max.

    public float[] getMax() {
final float[] max = new float[3];
max[0] = position.x + this.max.x;
max[1] = position.y + this.max.y;
max[2] = position.z + this.max.z;
//System.out.println(position);
return max;
}

public float[] getMin() {
final float[] min = new float[3];
min[0] = position.x - this.min.x;
min[1] = position.y - this.min.y;
min[2] = position.z - this.min.z;
return min;
}


• What do you mean by "not working"? – Vaillancourt May 16 '18 at 16:47

For people trying to implement an aabb vs aabb collision here is the code.

private static boolean checkFullCollision(Entity entity, Entity id1) {
// VERY INPORTANY. The max and min are centered at the origin(0,0) and not at the entities posititon.

Vector3f aextents = Vector3f.sub(entity.getModel().getMax(), entity.getModel().getMin(), null);
Vector3f bextents = Vector3f.sub(entity.getModel().getMax(), entity.getModel().getMin(), null);

boolean x = (abs(entity.getPosition().x - id1.getPosition().x) <= aextents.x + bextents.x);
boolean y = (abs(entity.getPosition().y - id1.getPosition().y) <= aextents.y + bextents.y);
boolean z = (abs(entity.getPosition().z - id1.getPosition().z) <= aextents.z + bextents.z);
return x && y && z;
}

• @AlexandreVaillancourt I will – user116458 May 17 '18 at 11:05
• @AlexandreVaillancourt see my other question – user116458 May 17 '18 at 11:07