Skip to content

physics

Bounded-cost geometric queries and Workspace raycasting against BasePart collision shapes.

physics.RaycastBox(origin: Vector3, direction: Vector3, cframe: CFrame, size: Vector3) -> RaycastResult | nil

Casts a ray segment from origin along direction against a single oriented box and returns a RaycastResult (Position, Normal, Distance, Instance=nil, Material=Plastic) on hit or nil on miss.

local hit = physics.RaycastBox(Vector3.new(0,10,0), Vector3.new(0,-20,0), part.CFrame, part.Size)
if hit then print(hit.Position) end

physics.PointInBox(point: Vector3, cframe: CFrame, size: Vector3) -> boolean

Returns true if point lies inside the oriented box defined by cframe and size.

local inside = physics.PointInBox(hrp.Position, part.CFrame, part.Size)

physics.PointInRegion3(point: Vector3, region: Region3) -> boolean

Returns true if point lies inside the axis-aligned bounds of a Region3.

local inside = physics.PointInRegion3(hrp.Position, region)

physics.Raycast([self: Instance,] origin: Vector3, direction: Vector3, [ignoreList: {Instance}]) -> RaycastResult | nil

Depth-first walks Workspace up to the configured instance budget and returns the closest BasePart hit along the ray as a RaycastResult, or nil on miss, rate limit, or when disabled; blocking and unsafe to call from a per-frame paint or update callback.

local result = physics.Raycast(Vector3.new(0,50,0), Vector3.new(0,-100,0), {character})
if result then print(result.Instance, result.Position) end

physics.RaycastBudget(n: number) -> ()

Sets the maximum number of Workspace instances examined per physics.Raycast call, clamped to at least 1.

physics.RaycastBudget(4000)

physics.RaycastEnabled(enabled: boolean) -> ()

Enables or disables physics.Raycast; while disabled every call returns nil immediately.

physics.RaycastEnabled(false)

physics.RaycastRate(castsPerSecond: number) -> ()

Caps how often physics.Raycast may fire per second, dropping over-rate calls as a miss (nil); a value of 0 or less removes the cap.

physics.RaycastRate(30)