Skip to content

Api > Physics > Linecast()


Physics.Linecast(PhysicLine physicLine)⚓︎

Returns true if there is any collider intersecting the line between start and end.

Parameters:⚓︎

Name Type Description
physicLine PhysicLine The physic line to cast.

Returns:⚓︎

type Description
boolean true if there is any collider intersecting the line.
RaycastHit hitInfo contain more information about where the collider was hit.

Usage⚓︎

---@type PhysicLine
local physicLine;


local val0, val1 = Physics:Linecast(physicLine)

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 line cast");
        local start = TestRayCasting.gameObject.transform.position;
        local _end = Vector3(0,-1,0);
    local hit, castInfo = Physics:Linecast(PhysicLine(start, _end));
    if (hit) then
            Debug.Log("Line cast succesful");
            Debug.Log("Cast dist: " .. tostring(castInfo.distance));
        end
    end
end