# Off Screen direction indicator HUD element / wrestling with Quaternion

 0 Hi I'm attempting to create a HUD element that appears if the players target has left the screen,its fixed to the edges of the screen and helps inform the player which way to turn to get them in the view again. my game has full 3d movement so it has to work with all possible rotations. I've almost got it working I'm just having trouble with constructing the quaternion that allows me easy access to the values I need. My current quaternion doesn't seam to take the roll into account correctly as so doesn't output the correct vector ``````Vector2 Offscreenindicator(Transform me,Transform target) { //Construct a Quaternion that has x and y euler angles relative to the players roll Quaternion test = Quaternion.LookRotation(target.position-me.position,-me.up)*me.rotation; //make those euler angles easily accessable Vector3 temp = test.eulerAngles; float pitch = temp.x; float yaw = temp.y; //calculate the horizontal FOV float Hfov = (2* Mathf.Atan(Mathf.Tan((pc.cam.fieldOfView * Mathf.Deg2Rad)/2)*pc.cam.aspect))*Mathf.Rad2Deg; //normalise the angles to a 180 to -180 system if(pitch > 180) pitch -= 360; if(yaw > 180) yaw -= 360; //clamp the angles to the edges of the screen then normalise them to 0 to there feild of view pitch = Mathf.Clamp(pitch,-pc.cam.fieldOfView/2,pc.cam.fieldOfView/2)+pc.cam.fieldOfView/2; yaw = Mathf.Clamp(yaw,-Hfov/2,Hfov/2)+Hfov/2; //compare with the feild of view to convert to a screen locaton pitch = (pitch / pc.cam.fieldOfView)*(Screen.height); yaw = (yaw/Hfov)*Screen.width; //return a value that can be used with GUI Components return new Vector2(yaw,pitch); } `````` more ▼ asked May 11 '11 at 04:58 PM Lord Simpson 143 ● 17 ● 18 ● 25 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 In the end replaced the whole idea with a pointer instead that is only a few cm [0.1] units big and floats a meter or so in front of the camera pointing to the target and moving towards it by a small degree. Also I deactivate the mesh render if the Vector3 angle between its pointing direction and the cameras forward vector are below 30 so it doesn't take up screen space when the target is obviously visible. If the target is directly behind you the pointer looks larger as its closer to the screen and points directly towards the camera. more ▼ answered Aug 08 '11 at 10:59 PM Lord Simpson 143 ● 17 ● 18 ● 25 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x3670
x437
x105
x7

asked: May 11 '11 at 04:58 PM

Seen: 1168 times

Last Updated: Aug 08 '11 at 10:59 PM