Raycasting positions help

I’ve never used raycasting before and was fallowing along with a tutorial and it wasn’t working for me. I tried fallowing the documentation and that also sis not work. Both the ray origin and the direction is off. The origin moves while I move the camera but the direction consistently points to one direction?

public Camera mainCamera;
Ray ray;
RaycastHit hitInfo;
// Start is called before the first frame update
void Start()
{
}

// Update is called once per frame
void Update()
{
/ray.origin = mainCamera.transform.position;
ray.direction = mainCamera.transform.TransformDirection(Vector3.forward);
Physics.Raycast(ray, out hitInfo);
transform.position = hitInfo.point;
/

Physics.Raycast(mainCamera.transform.position, mainCamera.transform.TransformDirection(Vector3.forward), out hitInfo);
Debug.DrawRay(ray.origin, hitInfo.point, Color.red, 1.0f);
}

TransformDirection generates a vector in world space, Vector3.forward = 0,0,1 so the output is always world space 0,0,1

Here are some examples

        Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hitInfo);
        Debug.DrawLine(mainCamera.transform.position, hitInfo.point, Color.red, 1.0f);
        Debug.DrawRay(mainCamera.transform.position, mainCamera.transform.forward * 10f, Color.blue, 1f);

You need to read the documentation carefully for each class and method you are using, for example the difference between DrawLine and DrawRay, the first uses a target position for the end of the line, the later uses a direction with magnitude to locate a point relative to the origin of the ray.