Physics.Raycast(PhysicRay physicRay)
Casts a ray, from point origin, in direction direction, of length maxDistance, against all colliders in the Scene.
Parameters:
Name | Type | Description |
---|---|---|
physicRay | PhysicRay | The physic ray to cast. |
Returns:
type | Description |
---|---|
boolean | true if the ray intersects with a Collider, otherwise false. |
RaycastHit | hitInfo contain more information about where the closest collider was hit. |
Usage
---@type PhysicRay
local physicRay;
local val0, val1 = Physics:Raycast(physicRay)
Example
do -- script TestRayCasting
-- get reference to the script
local TestRayCasting = LUA.script;
-- start only called at beginning
function TestRayCasting.Start()
Debug.Log("Making a ray cast");
local center = TestRayCasting.gameObject.transform.position;
local hit, castInfo = Physics:Raycast(PhysicRay(center, Vector3.forward));
if (hit) then
Debug.Log("Cast succesful");
Debug.Log("Cast dist: " .. tostring(castInfo.distance));
end
end
end