when my character goes onto a box that I am trying to make him collide with he gets stuck. The way I have it configured is that at the end of every frame, the characters x and y values are stored in old x and old y, and if he is colliding with the box his x and y are reverted to old x and old y. This seems to work when walking into the box, but when the character jumps on the box he gets stuck and can't move. I think this has something to do with his x and y being infinitely pushed to oldX and oldY, but I don't know how to fix this. Thanks for the help!
for(int x = 0; x < collidables.length; x++){
if(collidables[x] instanceof QuestionBox){
collidables[x].bottomCollision(mario);
}
if(mario.intersects(collidables[x].boxRectangle)){
mario.setMarioX(mario.oldX);
mario.setMarioY(mario.oldY);
}
}
mario.oldX = mario.getMarioX();
mario.oldY = mario.getMarioY();
Here is the code for what happens upon a collision. Thanks for the help!