# Direction the Playser faces: North, South,...

Discussion in 'Plugin Development' started by Zero9195, Jun 10, 2011.

Not open for further replies.
1. Offline

### Zero9195

Hi Guys,
I want to know how to get this Information, I can't find any solution for this in the API. I just got to the vectors, but these are not very helpfull. Thanks for Helping

#1
2. Offline

#2
3. Offline

Thank you

#3
4. Offline

### ScreamingAmish

I wrote this code because I wanted more than the 4 cardinal directions. Just pass it the Player and you'll get a human readable string with the direction. Hope it helps.

Code:
//
// rpGetPlayerDirection - Convert Player's Yaw into a human readable direction out of 16 possible.
//
public String rpGetPlayerDirection(Player playerSelf){
String dir = "";
float y = playerSelf.getLocation().getYaw();
if( y < 0 ){y += 360;}
y %= 360;
int i = (int)((y+8) / 22.5);
if(i == 0){dir = "west";}
else if(i == 1){dir = "west northwest";}
else if(i == 2){dir = "northwest";}
else if(i == 3){dir = "north northwest";}
else if(i == 4){dir = "north";}
else if(i == 5){dir = "north northeast";}
else if(i == 6){dir = "northeast";}
else if(i == 7){dir = "east northeast";}
else if(i == 8){dir = "east";}
else if(i == 9){dir = "east southeast";}
else if(i == 10){dir = "southeast";}
else if(i == 11){dir = "south southeast";}
else if(i == 12){dir = "south";}
else if(i == 13){dir = "south southwest";}
else if(i == 14){dir = "southwest";}
else if(i == 15){dir = "west southwest";}
else {dir = "west";}
return dir;
}

#4
PDKnight, Aengo and hammale like this.
5. Offline

### Zero9195

This is cool, I will add this to my Util if you don't mind

#5
6. Offline

### ScreamingAmish

Don't mind at all, happy I could help.

#6