Raycast from camera to mesh works incorrectly

Hi all

I have a such scene:

Now I want to cast a ray from camera straight forward to find a visual center point on my Earth.I do it by code:

RaycastHit hit;
Ray ray=Camera.main.ScreenPointToRay(Camera.main.transform.forward);
Physics.Raycast(ray,out hit,float.PositiveInfinity);
Vector3 center=transform.InverseTransformPoint(hit.point);

(Camera is rotated by 180o,but that does not infuence results as I made a check)
Yet this gives me unbelievable results,like (-8000,-8000) while something like (600,-0.75) is expected…What’s wrong with my code?

Moreover,I tried to use Debug.DrawRay() to check how really the ray is cast,but the ray was not visible,no matter if I set “gizmos” option or not :confused:

I solved the issue on my own-the ray has to be cast like:

Physics.Raycast(Camera.main.transform.position,Camera.main.transform.forward,out hit,float.PositiveInfinity);

and then it gives expected results :slight_smile: