Skip to main content

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x
    && player.rectangleMidPointX() < intersection.x) {
    // ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height
    && player.rectangleMidPointX() > intersection.x) {
    // ...
}

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x && player.rectangleMidPointX() < intersection.x) {
    ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height && player.rectangleMidPointX() > intersection.x) {
...
}

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x
    && player.rectangleMidPointX() < intersection.x) {
    // ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y + player.getRect().height
    && player.rectangleMidPointX() > intersection.x) {
    // ...
}
added 13 characters in body
Source Link
eyes enberg
  • 197
  • 2
  • 3
  • 11

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x coordinate-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x && player.rectangleMidPointX() < intersection.x) {
    ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height && player.rectangleMidPointX() > intersection.x) {
...
}

Found an easy solution to the problem. I just compared the midpoint of the player to the x coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x && player.rectangleMidPointX() < intersection.x) {
    ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height && player.rectangleMidPointX() > intersection.x) {
...
}

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x && player.rectangleMidPointX() < intersection.x) {
    ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height && player.rectangleMidPointX() > intersection.x) {
...
}
Source Link
eyes enberg
  • 197
  • 2
  • 3
  • 11

Found an easy solution to the problem. I just compared the midpoint of the player to the x coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the platform. Changed the if statements for left side and top side to:

// left side of platform
if (intersection.x > player.getRect().x && player.rectangleMidPointX() < intersection.x) {
    ...
}

// top side of platform
if (intersection.y + intersection.height < player.getRect().y
                            + player.getRect().height && player.rectangleMidPointX() > intersection.x) {
...
}