Help with Raycast

Hi i’ve read many forums / answers about raycast but after many tests neither suits me.

I woul’d like to be able to draw a raycast from the center of the screen, directly to the center of the camera on the ground. I’ve tried this :

        Ray ray = new Ray(cam.position, cam.forward);
		RaycastHit hit;
		if(Physics.Raycast(ray.origin, ray.direction * 1000, out hit, 5f))
			Debug.DrawLine (cam.position, hit.point);

Sorry for my bad english :wink:

when I ‘see my foot’ the raycast behaves strangely. It dishappears or it cuts.

Your ray starts from the cam position which is above the collider. When looking down, the ray hits the collider and then reports.

Now if you want to draw from a point to a point Linecast is more appropriate. Check layer to avoid hitting things you do not want to.

Raycast is for drawing from a point in a direction with distance (or not).