Skip to main content

Physics.Linecast(PhysicLine physicLine)

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

Parameters:

NameTypeDescription
physicLinePhysicLineThe physic line to cast.

Returns:

typeDescription
booleantrue if there is any collider intersecting the line.
RaycastHithitInfo 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