I am working on a platformer 2D, and i am currently focusing on collision. I have the actual rectangle(class: Rect) and i can detect if the player-model is intersepting it. However, when it comes from the side, that is when the problems appear: i can prevent it from going down after the interseption but i cant prevent it if it intersepts with the edges. how can I make a better collision system?
EDIT:
I have worked a little on a system, but it doesnt work. Help me improve this:
for(Platform p : game.platforms){
if(Rect.intersects(getBounds(), p.getBounds())){
coll = true;
int px = p.x;
int py = p.y;
if((x + 100) >= px && (x + 100) <= px + 10){
x = px - 101;
y += 100;
Toast.makeText(game.c, "if(x + 100) >= px && (x + 100) <= px + 10)", Toast.LENGTH_LONG).show();
} else if(y <= (py + 1) && y >= py + p.height + 10){
y = 0;
Toast.makeText(game.c, "if8y <= (py + 1) && y >= py + p.height + 10)", Toast.LENGTH_LONG).show();
} else if(y >= py ){
y = py - 100;
Toast.makeText(game.c, "if(y >= py", Toast.LENGTH_LONG).show();
}
}
}
if(!coll){
y += 6;
}else{
heightJumped = 0;
canJump = true;
isInAir = false;
jumping = false;
}
coll = false;
}