Can't get AABB Collision to work properly

This is the code I'm using to resolve collisions on the players left side. It works when I'm on the ground, but if I'm falling, it does not work.

public static boolean onWall(Rectangle rect1, Rectangle rect2){

if(rect1.x > rect2.x && rect1.x <= rect2.x + rect2.width && ((rect1.y > rect2.y && rect1.y < rect2.y + rect2.height) || rect1.y + rect1.height > rect2.y && rect1.y + rect1.height < rect2.y + rect2.height)){
rect1.x = rect2.x + rect2.width;
return true;
}

return false;

}

– user35344
Jan 2, 2019 at 7:02

Sorry finally figured it out, heres my code just in case anyone else needs help

public static boolean yCollision(Rectangle p, ArrayList<Rectangle> a, Vector2 v){
for(Rectangle r: a){
if(p.y + v.y <= r.y + r.height && ((p.x > r.x && p.x < r.x + r.width) || (p.x + p.width > r.x && p.x + p.width < r.x + r.width)) && p.y > r.y + (r.height / 2)){
p.y = r.y + r.height;
return true;
}
if(v.y > 0){
if(p.y + p.height + v.y > r.y && p.y + v.y + p.height < r.y + r.height && ((p.x > r.x && p.x < r.x + r.width) || (p.x + p.width > r.x && p.x + p.width < r.x + r.width)) && p.y > r.y){
p.y = r.y - p.height;
return true;
}
}
}
return false;
}

public static String xCollision(Rectangle p, ArrayList<Rectangle> a, Vector2 v){
for(Rectangle r: a){
if(p.x + v.x <= r.x + r.width && p.x + v.x >= r.x && ((p.y > r.y  && p.y < r.y + r.height) || (p.y + p.height > r.y && p.y + p.height < r.y + r.height))){
p.x = r.x + r.width;
return "left";
}
if(p.x + p.width + v.x >= r.x && p.x + p.width + v.x <= r.x + r.width && ((p.y > r.y  && p.y < r.y + r.height) || (p.y + p.height > r.y && p.y + p.height < r.y + r.height))){
p.x = r.x - p.width;
return "right";
}
}
return "none";
}

• This answer would be even better if it explained what you changed and why that solved the problem. Jan 3, 2019 at 2:23