# Determine where is player facing up, down or left right

I have a player object who can rotate(face using mouse) up, down left right and can face straight. I am willing to know that how to determine that where is camera facing? Either it is looking up or down?? while the player is continuously moving in a up/down surface.

Use dot products.

Assuming left, down, up, and right are global directions you dot the Camera fwd with each vector respectively (You actually only need to do two calculation because of how dot products work).

It would look something like this

//Will return between 1 and -1. 1 means left, -1 means right
float leftRight = Vector3.Dot(camFwd,Vector3.left);
//Will return between 1 and -1. 1 means up, -1 means down,
float upDown = Vector3.Dot(camFwd,Vector3.up);


Do whatever conditional checks you need to determine direction priority.

• did you test this code? left is not exists Apr 13, 2017 at 15:42
• Sorry, I made a typo, The 'l' in left should not have been capitalized. Apr 13, 2017 at 15:51
• Note that as written, you can get these numbers with less typing by upDown = cameraTransform.forward.y and leftRight = cameraTransform.forward.x (just note that this uses the opposite sign convention, with rightward directions positive) Aug 9, 2017 at 11:58

Have the game check the camera's rotation. If the camera's x rotation is around 90 degrees they are facing up. if the camera's x rotation is around -90 degrees they are facing down. if the camera's rotation x rotation is around 0 they are facing forward and if it is around 180 they are facing backwards. Then have the camera spawn a ray that is equal to the rotation of the camera and use mathf.aproxemetly to see which rotation is closest.