Ive been trying to get this working for a while but i just cant figure it out. I have an object in my scene that has a script attached to it that raycast from its position to the mouse position. however if i move the object from its initail position the raycast seems to have an offset of some sort. (Images Below)
Script (Attached to Cube) Here:
var AttachedCamera:Camera;
function Start () {
}
function Update ()
{
var MousePosition = this.AttachedCamera.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,15));
var hit:RaycastHit;
if (Physics.Raycast (transform.position, MousePosition,hit, 20))
{
Debug.DrawLine(this.transform.position, hit.point, Color.red);
Debug.Log(hit.point.x+","+hit.point.y);
}
Debug.DrawLine(this.transform.position, MousePosition, Color.blue);
}
How do i get rid of this offset?
thanks in advace