Physics¶
System · Physics · server and client scripts
Physics has the place-wide simulation settings, the collision groups, and the spatial queries against collider shapes. The server and each client step their own physics world, and a call acts on the world of the side that makes it.
To push one part, call Body:ApplyImpulse or set Velocity on it. For when physics runs relative to scripts, see PhysicsUpdate.
Replaying¶
Replaying is true while a predicted client physics step is replaying past inputs after a server correction, and false during normal simulation steps.
Default false
Collision groups¶
RegisterCollisionGroup¶
RegisterCollisionGroup adds a collision group named name. A part joins it when its CollisionGroup is set to that name. A new group collides with every group until SetCollides changes that. A place has 32 group slots, and Default, Character and CharacterNoCollide take three of them.
Example
Errors (1)
| Error | When |
|---|---|
RegisterCollisionGroup can only be called from the server |
Called from a client script. |
SetCollides¶
SetCollides sets whether parts of group a collide with parts of group b. Pass the same group twice to set whether it collides with itself.
Effects
- Spatial queries follow the rules only when their options name a
CollisionGroup. - Characters follow their group's rules for walking, standing, stepping, climbing and swimming.
Example
Errors (1)
| Error | When |
|---|---|
SetCollides can only be called from the server |
Called from a client script. |
Collides¶
Collides returns whether group a and group b are configured to collide.
Example
CollisionGroups¶
CollisionGroups returns the list of registered collision group names in slot order.
Explosion¶
Explode¶
Explode pushes dynamic bodies and characters away from center within radius units with linear falloff from the closest point on each collider, and returns the pushed root entities nearest first. impulse is the peak impulse at the center; a negative value pulls bodies in. Walls do not block the blast, and joints are exempt from the blast impulse unless options.BreakJoints is true.
Example
Errors (1)
| Error | When |
|---|---|
Explode can only be called from the server |
Called from a client script. |
Perception¶
EmitSound¶
EmitSound emits a sound at position that server listeners with Hearing hear within radius * Sensitivity units and returns how many listeners heard it. Optional options accepts Source (an entity that does not hear itself and provides the collision group) and Tag (a string of 1 to 255 bytes).
Example
Errors (1)
| Error | When |
|---|---|
EmitSound can only be called from the server |
Called from a client script. |
Queries¶
Raycast¶
Raycast(origin: Vector3, direction: Vector3, maxDistance: number, options: QueryOptions?) -> RaycastHit?
Raycast returns the first surface hit from origin along dir within maxDist units, or nil. The hit has Position, Normal, Entity, Distance, and LocalPosition and LocalNormal in the frame of the hit Entity.
A client ray tests every character's Head, Torso, arms and legs where that client draws them, so a ray at a character's Head returns that Head on a client as it does on a server. Only a server ray can rewind characters with AtTick.
Example
RaycastAll¶
RaycastAll(origin: Vector3, direction: Vector3, maxDistance: number, options: QueryOptions?, out: {RaycastHit}?) -> {RaycastHit}
RaycastAll casts a ray from origin along direction up to maxDistance units and returns every hit ordered nearest first. Pass out to reuse a preallocated table.
Example
Spherecast¶
Spherecast(origin: Vector3, radius: number, direction: Vector3, maxDistance: number, options: QueryOptions?) -> ShapecastHit?
Spherecast sweeps a sphere of radius from origin along direction up to maxDistance units and returns the first contact, or nil.
Example
SpherecastAll¶
SpherecastAll(origin: Vector3, radius: number, direction: Vector3, maxDistance: number, options: QueryOptions?, out: {ShapecastHit}?) -> {ShapecastHit}
SpherecastAll sweeps a sphere of radius from origin along direction up to maxDistance units and returns every contact nearest first. Pass out to reuse a table.
Example
Boxcast¶
Boxcast(origin: Vector3, size: Vector3, rotation: Rotation, direction: Vector3, maxDistance: number, options: QueryOptions?) -> ShapecastHit?
Boxcast sweeps an oriented box of full extents size and orientation rotation from origin along direction up to maxDistance units and returns the first contact, or nil.
Example
BoxcastAll¶
BoxcastAll(origin: Vector3, size: Vector3, rotation: Rotation, direction: Vector3, maxDistance: number, options: QueryOptions?, out: {ShapecastHit}?) -> {ShapecastHit}
BoxcastAll sweeps an oriented box of full extents size and orientation rotation from origin along direction up to maxDistance units and returns every contact nearest first. Pass out to reuse a table.
Example
Capsulecast¶
Capsulecast(origin: Vector3, radius: number, height: number, rotation: Rotation, direction: Vector3, maxDistance: number, options: QueryOptions?) -> ShapecastHit?
Capsulecast sweeps a capsule of radius, height, and orientation rotation from origin along direction up to maxDistance units and returns the first contact, or nil.
Example
CapsulecastAll¶
CapsulecastAll(origin: Vector3, radius: number, height: number, rotation: Rotation, direction: Vector3, maxDistance: number, options: QueryOptions?, out: {ShapecastHit}?) -> {ShapecastHit}
CapsulecastAll sweeps a capsule of radius, height, and orientation rotation from origin along direction up to maxDistance units and returns every contact nearest first. Pass out to reuse a table.
Example
OverlapSphere¶
OverlapSphere returns the entities whose shapes overlap a sphere. It fills out when you pass one, so a script can reuse one table.
Example
OverlapBox¶
OverlapBox(center: Vector3, size: Vector3, rotation: Rotation, options: QueryOptions?, out: {Entity}?) -> {Entity}
OverlapBox returns the entities whose shapes overlap an oriented box with full extents size and orientation rotation.
Example
OverlapCapsule¶
OverlapCapsule(center: Vector3, radius: number, height: number, rotation: Rotation, options: QueryOptions?, out: {Entity}?) -> {Entity}
OverlapCapsule returns the entities whose colliders overlap a capsule centered at center with radius, height, and orientation rotation. Pass out to reuse a table.