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
Name Type Description position vector Blast center in studs. radius number Blast radius in studs. force number Push force in newtons. returns number — - IsSleeping
(e: Instance) -> boolean whether the physics body of an entity sleeps
Parameters
Name Type Description e Instance Entity whose rigid body sleep state to test. returns boolean — - OverlapBox
(center: vector, half: vector, rotation: vector?, out: {Instance}?) -> (number, {Instance}) collect the entities inside a rotated box
Parameters
Name Type Description center vector Box center in studs. half vector Half-extents in studs from the center. rotation vector? 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
Name Type Description center vector Sphere center in studs. radius number Sphere 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
Name Type Description origin vector Ray start in studs. dir vector Ray direction vector. maxDist number Ray length in studs. ignore Instance? Entity to skip, along with its descendants. returns RaycastResult? — - RegisterCollisionGroup
(name: string) -> ()[server] register a named collision group
Parameters
Name Type Description name string Name for the new collision group. returns () — - RenameCollisionGroup
(from: string, to: string) -> ()[server] rename a collision group
Parameters
Name Type Description from string Current group name. to string New group name. returns () — - SetCollisionRule
(a: string, b: string, collidable: boolean) -> ()[server] set whether two groups collide
Parameters
Name Type Description a string First collision group name. b string Second collision group name. collidable boolean Whether 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
Name Type Description shape string One of "box", "sphere", or "capsule". size vector Extents of the shape in studs. from vector Sweep start in studs. to vector Sweep end in studs. rotation vector? 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.
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