Please reference the attached image.
I am raycasting using the following code…
#pragma strict
var hit : RaycastHit;
function Update () {
var fwd = transform.TransformDirection(transform.forward);
Debug.DrawRay(transform.position, fwd*100, Color.green);
if(Physics.Raycast(transform.position, fwd, hit, 100)) {
if(hit.collider.gameObject.tag == "HumpbackWhale") {
print("You just found a Humpback Whale");
}
}
}
I am using NGUI to display the compass/crosshair, with the NGUI UI Root parented to a
FPC/main cam. I am casting the ray from the main cam of the FPC. As long as all the rotations for the FPC are zero the ray lines up nicely with the center of the crosshair. Once I start rotating the FPC/maincam with the mouse the ray seems to rotate more than the FPC/main cam. As shown in the image if I rotate the FPC so that it is “looking” below the horizon the ray intersects the sphere before the crosshairs gets centered. Same thing happens rotating left or right. The ray always gets ahead of where the FPC is “looking”. Not sure why this is happening. Could someone give me some help.