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);
}