How to keep raycast lined up with main camera & cross hair center

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,;

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.

What happens if you don’t use TransformDirection, and instead just feed transform.forward into your Raycast?

I just tried this to make sure, and it works fine:

using UnityEngine;
using System.Collections;

public class Raycast : MonoBehaviour
	RaycastHit hit;
	void Update()
		Ray ray = new Ray(transform.position, transform.forward);
		Physics.Raycast(ray, out hit, float.PositiveInfinity);
	void OnDrawGizmos()
		Gizmos.DrawLine(transform.position, hit.point);