Api > Collider > Raycast()
Collider.Raycast(Ray ray, number maxDistance)
Casts a Ray that ignores all Colliders except this one.
Parameters:
Name |
Type |
Description |
ray |
Ray |
The starting point and direction of the ray. |
maxDistance |
number |
The max length of the ray. |
Returns:
type |
Description |
boolean |
True when the ray intersects the collider, otherwise false. |
RaycastHit |
If true is returned, hitInfo will contain more information about where the collider was hit. |
Usage
---@type Collider
local collider;
---@type Ray
local ray;
---@type number
local maxDistance;
local val0, val1 = collider.Raycast(ray, maxDistance)
Example
local didHit, hitInfo = someCollider.Raycast(Ray(Vector3.zero, Vector3.forward), 50);