I'm trying to get the collision between two squares. I've made a Rectangle
object that overlays each one and updates the position every tick.
Then I made a collision method that checks whether they are intersecting or not. It just uses rectangle1.intersects(rectangle2);
That works fine, and it detects the collision, however I can't move when it detects it.
This is my move and collision method at the moment.
public void move(int xa, int ya, Player opponent) {
if (collision(opponent)) {
return;
}
this.x += xa;
this.y += ya;
}
public boolean collision(Player opponent) {
if (rectangle.instersects(opponent.rectangle) return true;
return false;
}
The detection and stuff works fine, but I can't move. I see why I can't, because the method is returning before it moves anything, but I'm just completely lost for whatever reason on where to go with it. I'm sure it's an easy fix and I'm just not seeing something.