I am trying to draw a raycast from the camera to the object that the camera has a smoothfollow on I just can’t find the value for the direction of the ray, forward does not work when the camera looks down and transform.rotation gives a quantern when the method requires a Vector3
var hit : RaycastHit;
if (Physics.Raycast (theCamera.transform.position, -Vector3.right, hit, 20000.0))
{
Debug.DrawLine (theCamera.transform.position, hit.point);
Debug.Log(hit.collider.gameObject.tag);
}
I want to know what I am looking at
It looks like the vector you are providing for the ray (-Vector3.right) is the world right vector.
Have you tried:
if (Physics.Raycast (theCamera.transform.position, theCamera.tranform.forward, hit, 20000.0))
Or is that what you meant when you said you tried using forward?
thanks Juan but that still doesn’t angle it down correctly
If you want to raycast from one point to another (eg: the camera’s position to the camera target’s position), you would do:
var dirToTarget : Vector3 = Vector3(target.transform.position - theCamera.transform.position).normalized;
if (Physics.Raycast(theCamera.transform.position, dirToTarget, hit, 20000.0))
That was perfect legend thanks