Luduvo Contents
Theme
On this page

Physics

queries the physics world with rays, overlaps, and sweeps, and sets the collision groups and gravity the solver uses

Properties

2 members

FallenPartsDestroyHeight: number [read only]

height where fallen parts vanish

Gravity: number [server]

downward acceleration

Methods

10 members

DrainTouchEvents() -> ({TouchEvent}, boolean)

drain the buffered touch begin and end events, second result reports lost events

Explode(position: vector, radius: number, force: number) -> number [server]

break the welds inside a sphere and push the bodies out, result counts the bodies pushed

Parameters
NameTypeDescription
positionvectorBlast center in studs.
radiusnumberBlast radius in studs.
forcenumberPush force in newtons.
returnsnumber—
IsSleeping(e: Instance) -> boolean

whether the physics body of an entity sleeps

Parameters
NameTypeDescription
eInstanceEntity whose rigid body sleep state to test.
returnsboolean—
OverlapBox(center: vector, half: vector, rotation: vector?, out: {Instance}?) -> (number, {Instance})

collect the entities inside a rotated box

Parameters
NameTypeDescription
centervectorBox center in studs.
halfvectorHalf-extents in studs from the center.
rotationvector?Euler angles in radians; nil keeps the box axis-aligned.
out{Instance}?Table that receives the entities; the call allocates one when nil.
returns(number, {Instance})—
OverlapSphere(center: vector, radius: number, out: {Instance}?) -> (number, {Instance})

collect the entities inside a sphere

Parameters
NameTypeDescription
centervectorSphere center in studs.
radiusnumberSphere radius in studs.
out{Instance}?Table that receives the entities; the call allocates one when nil.
returns(number, {Instance})—
Raycast(origin: vector, dir: vector, maxDist: number, ignore: Instance?) -> RaycastResult?

cast a ray and report the first hit

Parameters
NameTypeDescription
originvectorRay start in studs.
dirvectorRay direction vector.
maxDistnumberRay length in studs.
ignoreInstance?Entity to skip, along with its descendants.
returnsRaycastResult?—
RegisterCollisionGroup(name: string) -> () [server]

register a named collision group

Parameters
NameTypeDescription
namestringName for the new collision group.
returns()—
RenameCollisionGroup(from: string, to: string) -> () [server]

rename a collision group

Parameters
NameTypeDescription
fromstringCurrent group name.
tostringNew group name.
returns()—
SetCollisionRule(a: string, b: string, collidable: boolean) -> () [server]

set whether two groups collide

Parameters
NameTypeDescription
astringFirst collision group name.
bstringSecond collision group name.
collidablebooleanWhether the two groups generate contacts.
returns()—
Shapecast(shape: string, size: vector, from: vector, to: vector, rotation: vector?, out: {ShapecastHit}?) -> (number, {ShapecastHit})

sweep a box, a sphere, or a capsule and report every entity in the path, nearest first

Parameters
NameTypeDescription
shapestringOne of "box", "sphere", or "capsule".
sizevectorExtents of the shape in studs.
fromvectorSweep start in studs.
tovectorSweep end in studs.
rotationvector?Euler angles in radians; nil keeps the shape axis-aligned.
out{ShapecastHit}?Table that receives the hits; the call allocates one when nil.
returns(number, {ShapecastHit})—

Raycasting and Applying Contact Forces

Lifecycle: Server

A downward ray is the usual way to find the ground under an entity and push back against it.

Luau
local origin = Vector3.new(0, 10, 0)local dir = Vector3.new(0, -1, 0)local maxDist = 50local hit = game.Physics.Raycast(origin, dir, maxDist)if hit then	print(string.format("Hit entity %s at distance %.2f", tostring(hit.Entity), hit.Distance))	local contactForce = hit.Normal * -250	hit.Entity:ApplyForce(contactForce, hit.Position)end