GetRayIntersection
Cast a 3D ray against the 2D Colliders in the Scene.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
GetRayIntersection(Ray, float, int)
Cast a 3D ray against the 2D Colliders in the Scene.
public static RaycastHit2D GetRayIntersection(Ray ray, float distance, int layerMask = -5)
Parameters
Returns
Type | Description |
|---|---|
| RaycastHit2D | The ray intersection result. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.
NOTE: All results are sorted into ascending distance order i.e. the first result is the closest.
GetRayIntersection(Ray, float, List<RaycastHit2D>, int)
Cast a 3D ray against the 2D Colliders in the Scene.
public static int GetRayIntersection(Ray ray, float distance, List<RaycastHit2D> results, int layerMask = -5)
Parameters
The 3D ray defining origin and direction to test.
The maximum distance over which to cast the ray.
The list to receive the results.
The LayerMask filter used to select which layers to detect Colliders for.
Returns
Type | Description |
|---|---|
| int | The number of RaycastHit2D results returned. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.
NOTE: All results are sorted into ascending distance order i.e. the first result is the closest.