- Home /
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?
Answer by Glurth · Jan 30, 2018 at 08:03 PM
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).
https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
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". (https://docs.unity3d.com/ScriptReference/Vector3-magnitude.html)
e.g.
//given `Vector3 origin` and `Vector3 endPoint` values
Vector3 offset=endPoint-origin;
RaycastHit2D hitResult=Raycast(origin, offset, offset.magnitude);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to implement authorization URL opening in browser to get auth code? 0 Answers
How to rotate a GameObject with another GameObject while simulating gravity? 2 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer