What is wrong with my raycast

Hi

I’m trying to cast a ray from the camera straight down. How would I do this?

My code

Ray rayDown = new Ray(transform.position, Vector3.down );
RaycastHit hitDown;

if(Physics.Raycast(rayDown, out hitDown, Mathf.Infinity))
    Debug.DrawRay(rayDown.origin, hitDown.point, Color.red);

The ray starts off going from the camera straight down but if the camera moves the ray will angle its self and will no longer be pointing down.

3975-start.jpg
3976-finishpng.jpg

Thanks

Your problem is not the ray cast its the Debug.DrawRay

The way you are calling it - the second parameter should be the (hit.point - rayDown.origin) as it is a direction not a point.