Determine length of Debug.DrawRay ray

So I am running into some issues with seeing an extremely short line when I am drawing a ray using debug.DrawRay. I’m trying to setup a visible rayCast gizmo to get a visualization of the control ray I am using to move my character. Here’s the code I am using to do this.

bool interactionRay (Vector3 location) {
  		Ray ray = Camera.main.ScreenPointToRay(location);
   		Debug.DrawRay(ray.origin, ray.direction,;
   		return Physics.Raycast(ray, out hit);

I was under the impression that a ray was supposed to cast for an infinite direction until it hits something, however in the editor this is what I am seeing.


The raycast is obviously working since the character is pathing to it’s strike point however the debug ray is not following the same path. It’s not even reaching down into a place where it’s visible by the game camera. Any idea why this might happen? Have I misunderstood how the Debug ray drawing gizmo works? I don’t see any option in the ray object itself to set it’s length.

You can set the distance that the Debug Ray will draw.

Debug.DrawRay(ray.origin, ray.direction * raycastDistance,, duration);

You simply multiply the Direction by a distance (float). I use the same distance variable I use to cast the actual ray and it works beautifully.

The direction in DrawRay has a length. In Raycast, the distance is Mathf.Infinity by default. So your DrawRay and Raycast are different; you could use ray.direction*Mathf.Infinity in DrawRay to make them the same.

If the yellow line is your correct raycast and the green line is your debug ray, then I’m sure that:

You are drawing the Camera.main.ScreenPointToRay()'s ray, not your Physics.Raycast()'s ray. (That’s why they are in a different location)

By this Debug.DrawRay script ref, in your code, the Debug.DrawRay() will draw for only one frame because the duration parameter is 0 by default.