Skip to main content

Physics.SphereCast(PhysicSphere physicSphere)

Casts a sphere along a ray and returns detailed information on what was hit.

Parameters:

NameTypeDescription
physicSpherePhysicSphereThe PhysicSphere to cast.

Returns:

typeDescription
booleanTrue when the sphere sweep intersects any collider, otherwise false.
RaycastHithitInfo contain more information about where the collider was hit.

Usage

---@type PhysicSphere
local physicSphere;


local val0, val1 = Physics:SphereCast(physicSphere)

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 sphere cast");
local center = TestRayCasting.gameObject.transform.position;
local hit, castInfo = Physics:SphereCast(PhysicSphere(center, 10, Vector3.forward));
if (hit) then
Debug.Log("Cast succesful");
Debug.Log("Cast dist: " .. tostring(castInfo.distance));
end
end
end