xlDino Posted May 17, 2023 Share Posted May 17, 2023 (edited) This method finds what direction the player is facing based on the previous tile, and assigns it to the 'direction' string. private void checkPlayerDirection() { int currentX = myPlayer().getX(); int currentY = myPlayer().getY(); int deltaX = currentX - previousX; int deltaY = currentY - previousY; if (deltaX == 0 && deltaY == 0) { direction = previousDirection; // Use the previous direction when not moving } else if (deltaX == 0) { direction = deltaY > 0 ? "North" : "South"; } else if (deltaY == 0) { direction = deltaX > 0 ? "East" : "West"; } else if (deltaX > 0) { direction = deltaY > 0 ? "North-East" : "South-East"; } else { direction = deltaY > 0 ? "North-West" : "South-West"; } if (!direction.equals(previousDirection)) { log("Player is facing: " + direction); previousDirection = direction; } } onStart previousX = myPlayer().getX(); previousY = myPlayer().getY(); onLoop checkPlayerDirection(); previousX = myPlayer().getX(); previousY = myPlayer().getY(); Variables int previousX; int previousY; String direction; String previousDirection; Usage if(direction == "North") { //do something } Edited May 17, 2023 by xlDino Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted May 18, 2023 Share Posted May 18, 2023 (edited) You can simply check the rotation of a player, might be easier than checking it like that myPlayer().getRotation() If you enable myPlayer debug in the debug tab, it will be included. If interacting with an entity these values sometimes shift a little bit. 0 = South 256 = South-West 512 = West 768 = North-West 1024 = North 1280 = North-East 1536 = East 1792 = South-East Edited May 18, 2023 by Khaleesi Quote Link to comment Share on other sites More sharing options...
xlDino Posted May 18, 2023 Author Share Posted May 18, 2023 2 hours ago, Khaleesi said: You can simply check the rotation of a player, might be easier than checking it like that myPlayer().getRotation() If you enable myPlayer debug in the debug tab, it will be included. If interacting with an entity these values sometimes shift a little bit. 0 = South 256 = South-West 512 = West 768 = North-West 1024 = North 1280 = North-East 1536 = East 1792 = South-East Found this out after hahahahaha 1 Quote Link to comment Share on other sites More sharing options...