The collection detection method I'm using currently can interpret a collision, but causes strange effects depending on the direction. It will:
- Always work if the player is hitting the right side of the object.
- Push the player to the side if the player is hitting the top or bottom of the object.
- Work the first time if the player is hitting the left side of the object, but will teleport the player to the opposite side of the object the next time a collision is detected on the left side.
This is the current collision detection code:
if(player.playerBounds.intersects(portal.bounds)&&player.isMovingLeft){
player.playerX=(portal.x+portal.width);
player.playerX++;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingRight){
player.playerX=(portal.x-player.width);
player.playerX--;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingUp){
player.playerY=(portal.y+portal.height);
player.playerY--;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingDown){
player.playerY=(portal.y+player.height);
player.playerY++;
}