# How do i get the X,Y and Z of the way my unit is facing?

I have the yaw and pitch of my unit at my disposal, I know if I use polar to cartesian conversion I'll get the X and Y of each one of those two, but I need them combined to give me the x,y and z of the direction I'm facing.

-
is it safe to assume that Roll=0? I can't remember ever being able to roll in Minecraft. – Jordaan Mylonas Sep 4 '11 at 22:47

If you're using a regular Unity GameObject, you can just use `transform.forward` to access the forward direction of your object. See the Unity documentation for details.

If you're using a different way to track your object, Spherical coordinates are essentially polar coordinates expanded with a third dimension.

EDIT: I assume in Minecraft `z` is the vertical axis and `x` and `y` are on the horizontal plane. If this isn't the case, the principles would still apply but the `x`, `y`, and `z` would need to be assigned differently:

The `x` and `y` directional components can be determined from the yaw fairly easily: `x = sin(yaw)` and `y = cos(yaw)`. I'm not familiar with modding Minecraft to know whether or yaw is in degrees or radians—you may need to convert it in order to get real results from those trig functions. It's also possible that you may need to add a constant to the yaw to match the actual axes in the game (like adding or subtracting 90° to align with the world axes).

The `z` component can be determined from the pitch: `z = cos(pitch)`. Again, you may need to convert between degrees and radians or add a constant to match world axes.

-
I'm modding a game named Minecraft, it has it's own engine and it doesn't have unity GameObject, how do i know how they track the object? – Rodrigo Cavalcante Sep 4 '11 at 15:54
@Rodrigo then why did you add the Unity tag? – Tetrad Sep 4 '11 at 17:57
It was supposed to be unit, sorry. How do i replace it? – Rodrigo Cavalcante Sep 4 '11 at 19:46
Edited my response to fit what it sounds like you're looking for regarding Minecraft. – chaosTechnician Sep 5 '11 at 4:07
Minecraft uses degrees (with the `float` data type), and `y` is pointing "up". Position of an entity is stored as a triplet of the `double` data type. – Martin Sojka Sep 5 '11 at 11:10

If you have the Yaw and Pitch giving you the X and Y, can't you just assuming your roll (Z) is 0? Most game characters don't allow you to rotate on that axis.

-
Converting to Cartesian the pitch gives me an X and Y and the same goes for yaw, but i need them combined to give me Z to, because i'm using this to calculate the angle between my view direction and another unit in the vertical direction. – Rodrigo Cavalcante Sep 4 '11 at 20:08