Lenght of ray from Physics2D

Is direction parametr in Physics2D.RayCast describe how long is ray from point A to B? Like in Debug.DrawRay?

The default length of such a ray is Infinity, as defined by the THIRD(optional) “distance” parameter to this function.

So, the vector provided to “direction” would be normalized, then multiplied by the distance parameter, to get the endpoint of the ray (relative to the origin).

The float distance = Mathf.Infinity part of the definition means that; the Mathf.Infinity value will be assigned that parameter, if you do NOT specify one. It makes the parameter optional.

If you have an “offset” vector that you want to use, you can use provide it as the direction parameter(it will be normalized), and the magnitude of that vector for your “distance”. (Unity - Scripting API: Vector3.magnitude)

e.g.

//given `Vector3 origin` and `Vector3 endPoint` values
Vector3 offset=endPoint-origin;
 RaycastHit2D hitResult=Raycast(origin, offset, offset.magnitude);