Physics: constraints, assemblies, network ownership

Learn Roblox physics from Beacon Yard's exhibit. A hinged sign, a roped crate and welded meshes teach constraints, assemblies and network ownership, and why the drone stays anchored.

Concept lesson, about 85 minutes, 11 steps

By the end you can

  • Join parts with HingeConstraint, RopeConstraint and WeldConstraint and predict how each moves
  • Explain what an assembly is and why anchoring one part changes the whole assembly
  • Decide which machine should simulate a part, and when to keep it on the server
  • Filter collisions with collision groups, and let players drag a part with a DragDetector the server checks

Before this: The drone: movement, targeting, damage, NPCs and pathfinding: the scrap crawler

1Push the sign

In the south-west corner of the yard there is a small exhibit: a wooden sign on a post, a crate tied to a metal hitch, and a lamp. Walk into the sign and it swings away from you, then settles. Shove the crate and it slides until the rope goes tight. No script moves either of them after Play starts.

Figure 1.1.

The sign swings on a hinge with no motor; the crate stops when its 8-stud rope is tight.

Transcript
  1. 0:04 The sign swings on SignHinge. Nothing motors it back.
  2. 0:09 The limits are minus 55 and plus 55 degrees.
  3. 0:12 The rope stops the crate at 8 studs.

The physics engine moved them. ExhibitService arrives at m06-drone-wrench (the milestone this lesson's BuildAlong moves you to from m05-the-round) and only builds the parts and the joints once at boot. This lesson is about those joints, called ConstraintConstraintA physics joint between two attachments, such as a hinge, rope, weld or spring.Think of it as a hinge, a rope or glue between two parts.s, and about who runs the physics.

After Play starts, what moves the sign when you walk into it?

  1. The physics engine, because the sign is unanchored and joined by a hinge
  2. ExhibitService, which sets the sign's CFrame every frame
  3. Your client, through a remote
  4. A tween started by the round
Answer

The physics engine, because the sign is unanchored and joined by a hinge. ExhibitService builds the exhibit once. The sign is unanchored, so the solver moves it when your character collides with it, within the hinge's limits.

Open this step in lesson mode · Link to this step · This confused me

2A hinge: rotation around one axis

A HingeConstraint joins two attachments so the parts can only rotate around one shared axis: Attachment0's X axis1. The post is anchored; the sign is not, so the sign is the part that turns.

	local hinge = Instance.new("HingeConstraint")
	hinge.Name = "SignHinge"
	hinge.Attachment0 = hingeAttachment(post, "HingePost", hingeOnPost)
	hinge.Attachment1 = hingeAttachment(sign, "HingeSign", signAttach)
	hinge.ActuatorType = Enum.ActuatorType.None
	hinge.LimitsEnabled = true
	hinge.LowerAngle = -55
	hinge.UpperAngle = 55
	hinge.Restitution = 0.15
	hinge.Parent = post
Figure 2.1

ActuatorType decides whether the hinge drives itself. Motor spins at an angular velocity, Servo turns to a target angle, and None, used here, does nothing on its own. Limits keep the swing between -55° and 55°, and Restitution 0.15 makes the sign bounce only a little off those stops.

LowerAngle is -55 and UpperAngle is 55. Through how many degrees can the sign swing from one stop to the other?

Answer

110 degrees. 55 + 55 = 110 degrees. A gentle push stays well inside that; the limits only matter when someone runs into the sign.

Open this step in lesson mode · Link to this step · This confused me

3A rope: a maximum, not a rod

A RopeConstraint keeps two attachments from getting farther apart than its Length. They may come closer; then the rope is slack2. CrateRope ties the top of the hitch to the top of the crate with a length of 8.

	local rope = Instance.new("RopeConstraint")
	rope.Name = "CrateRope"
	rope.Attachment0 = pointAttachment(hitch, "RopeHitch", Vector3.new(0, hitch.Size.Y / 2, 0))
	rope.Attachment1 = pointAttachment(crate, "RopeCrate", Vector3.new(0, CRATE_SIZE.Y / 2, 0))
	rope.Length = ROPE_LENGTH
	rope.Visible = true
	rope.Thickness = 0.12
	rope.Color = BrickColor.new("Cocoa")
	rope.Parent = hitch
Figure 3.1
Luau
local LENGTH = 8
local function ropeState(hitch, crate)
	local dx, dy, dz = crate[1] - hitch[1], crate[2] - hitch[2], crate[3] - hitch[3]
	local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
	return if distance >= LENGTH then "taut" else "slack"
end
print(ropeState({ -23, 8, -24 }, { -19, 3.5, -20 }))
print(ropeState({ -23, 8, -24 }, { -17, 3.5, -19 }))
Figure 3.2. Expected output: slack taut

Someone sets crate.Anchored = true in ExhibitService. What happens when you shove the crate?

local crate = part(exhibit, "Crate", CRATE_SIZE, position, color, Enum.Material.WoodPlanks, true)
  1. Nothing; anchored parts are not simulated, so the crate stays put
  2. It slides until the rope is tight, as before
  3. The rope pulls the hitch over
  4. The rope breaks
Answer

Nothing; anchored parts are not simulated, so the crate stays put. The solver never moves an anchored part. The crate becomes a wall, and the rope can only ever be slack or exactly tight.

Open this step in lesson mode · Link to this step · This confused me

4Welds and assemblies

A WeldConstraint holds two parts in the same position relative to each other, touching or not3. Parts joined by welds move as one rigid body, an assembly. Movable joints such as hinges join assemblies into a bigger mechanism4.

Beacon Yard uses welds to hang uploaded meshes on gameplay parts. The coin, the drone and the beacon each clone their mesh, switch off its collision, touch and query, make it Massless, and weld it to the invisible part the game actually uses. The drone's root is anchored and its mesh copies Anchored from it, so that weld joins two anchored parts and is inactive. The mesh follows because PivotTo moves the whole model. A weld does its real work on unanchored parts, such as a crate.

			descendant.Anchored = parent.Anchored
			descendant.CanCollide = false
			descendant.CanTouch = false
			descendant.CanQuery = false
			descendant.Massless = true
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = parent
			weld.Part1 = descendant
			weld.Parent = descendant
Figure 4.1

Massless matters: a heavy mesh welded to a light part would change how the assembly moves. Switching off CanQuery and CanTouch keeps the costume out of raycasts and touch events, so the art can change without changing the game.

An unanchored crate has a large, decorative metal mesh welded to it, with Massless off. What changes?

  1. The crate assembly gets much heavier and harder to push
  2. Nothing; welded parts never add mass
  3. The mesh falls off
  4. The crate becomes anchored
Answer

The crate assembly gets much heavier and harder to push. An assembly's mass is the sum of its parts. Massless removes a decorative part from that sum, which is why the meshes in Beacon Yard set it.

Open this step in lesson mode · Link to this step · This confused me

5Who runs the physics

Physics in Roblox is shared out. The server always owns anchored parts. For unanchored parts, the engine gives the simulation to a nearby player's device, so pushing the crate feels instant for the player doing it5. That machine is the part's network owner.

Both sidesRemember: Network ownership is whoever holds the ball.

Through m06-drone-wrench, Beacon Yard never calls SetNetworkOwner (the scrap crawler at m08-crawler is the first to). The sign and the crate follow the default rule, and that is fine for loose props. The drone is the opposite case. Its root is anchored, so the server always owns it, and no client can ever move the part the wrench raycast is aimed at.

Roblox Studio
Roblox Studio during Play showing the physics exhibit in the yard: the hinged sign reading Physics, Push the sign, the wooden crate, the lamp post, and the HUD.

Select a numbered pin, or a row below, to read what it marks.

Figure 5.1.

The exhibit at rest. Select a pin to see which constraint holds each part.

A player stands right next to the crate and nobody has called SetNetworkOwner. Which machine most likely simulates the crate?

  1. That player's client
  2. The server, always
  3. Every client at once
  4. Nobody until the crate is touched
Answer

That player's client. By default ownership follows proximity. The nearby player's device simulates the crate and its positions replicate to the server and to everyone else.

Open this step in lesson mode · Link to this step · This confused me

6Where the ball picture breaks

Holding a ball means you control it, and that is the problem. Answer first, then open the breakdown.

Where does it break?“Whoever holds the ball” is a good picture of network ownership. Where does it stop being true?

It breaks here. The server can take the ball back at any time and always keeps anchored parts, and the holder is trusted with positions it reports, so a cheating holder can move the ball anywhere.

The true model. Each unanchored assembly is simulated by one machine. Clients near it usually own it for responsiveness; their simulated positions replicate to the server. Anything gameplay-critical is anchored or kept server-owned, and the server validates results instead of trusting the owner.

Match each object to the ownership it should have.

  1. The exhibit crate
  2. The drone's root
  3. The scrap crawler's root (from m08)
  4. A car the player drives
Answer

The exhibit crate: Default: a nearby client may own it; The drone's root: Anchored, so always the server; The scrap crawler's root (from m08): Unanchored, kept on the server with SetNetworkOwner(nil); A car the player drives: The driver, with SetNetworkOwner(player). Props can follow the default. Anything that decides damage or score stays with the server, either anchored or with SetNetworkOwner(nil). A vehicle is given to its driver so steering feels instant.

Open this step in lesson mode · Link to this step · This confused me

7Build it: the exhibit

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
ConstraintsHinge, rope, spring, prismatic and mover constraints solved by the physics engine.Doors, signs, ropes, vehicles: anything that should react to collisions. What the exhibit uses.Behaviour depends on mass and ownership, and is harder to make exactly repeatable.
Tweens on anchored partsTweenService moves an anchored part along a fixed curve.Gates, lifts and anything that must end in an exact place, like Beacon Yard's gates.No physical reaction; a player standing in the way is pushed or clipped.
Scripted CFrame each frameThe server sets a CFrame on Heartbeat, as the drone does.Enemies and hitboxes that must be server-authoritative.You write the motion, and moving a part this way never fires Touched.
  • src/server/ExhibitService.luau
  • src/server/init.server.luau
  1. In the game repo, run git diff m05-the-round m06-drone-wrench -- src/server/init.server.luau and open src/server/ExhibitService.luau at m06-drone-wrench.

    You should see ExhibitService.luau is new, and init.server.luau calls ExhibitService.start(map.yard) right after RoundService.start.

  2. Run rojo serve, connect Studio, press Play and expand the exhibit in Explorer.

    You should see Workspace.Yard.PhysicsExhibit holds SignPost, Sign, Hitch, Crate, LampPost and Lamp, with SignHinge under the post and CrateRope under the hitch.

  3. Switch to the Server view, select SignHinge, then switch back and walk into the sign.

    You should see Pushing the sign makes it swing and settle; CurrentAngle on SignHinge changes in the Properties window and stays between -55 and 55.

  4. Push the crate away from the hitch.

    You should see The crate stops moving away once the rope is drawn as a straight line between the hitch and the crate.

Open this step in lesson mode · Link to this step · This confused me

8Who blocks whom: collision groups

At m14-ship the yard has a drone and a scrap crawler. Before you change anything, predict what happens when they meet.

The drone flies straight through the spot where the crawler is walking. What happens?

root.Anchored = true
root.CanCollide = false -- the drone's root, in DroneService
  1. They pass through each other; the drone is not solid and is moved by PivotTo, so nothing blocks it
  2. The crawler is knocked over by the drone
  3. The drone stops in front of the crawler
  4. Both stop, because two solid enemies cannot overlap
Answer

They pass through each other; the drone is not solid and is moved by PivotTo, so nothing blocks it. The drone already passes through everything. A collision group would change nothing between these two. Groups matter for parts that are solid.

The crawler is solid, and so are players. Two problems follow. Players crowd the coin pads and block each other, and a few players standing in a gap between scrap stacks can wall the crawler in. A collision group fixes both. Every part has a CollisionGroup name, "Default" unless you change it, and a table of rules says which groups collide. Register groups and set rules with workspace:RegisterCollisionGroup and workspace:CollisionGroupSetCollidable; the old PhysicsService versions are deprecated. Do it from one script, because script order is not guaranteed. Studio shows the table in Window ⟩ 3D ⟩ Collision Groups6.

luau
-- src/server/CollisionRules.luau, started first in init.server.luau
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
 
local CollisionRules = {}
 
local function put(part: Instance, group: string)
	if part:IsA("BasePart") then
		part.CollisionGroup = group
	end
end
 
function CollisionRules.start()
	workspace:RegisterCollisionGroup("Players")
	workspace:RegisterCollisionGroup("Crawler")
	workspace:CollisionGroupSetCollidable("Players", "Players", false)
	workspace:CollisionGroupSetCollidable("Players", "Crawler", false)
 
	local function onCharacter(character: Model)
		for _, part in character:GetDescendants() do
			put(part, "Players")
		end
		character.DescendantAdded:Connect(function(part)
			put(part, "Players")
		end)
	end
	local function onPlayer(player: Player)
		player.CharacterAdded:Connect(onCharacter)
		if player.Character then
			onCharacter(player.Character)
		end
	end
	Players.PlayerAdded:Connect(onPlayer)
	for _, player in Players:GetPlayers() do
		onPlayer(player)
	end
 
	CollectionService:GetInstanceAddedSignal("Crawler"):Connect(function(root)
		put(root, "Crawler")
	end)
end
 
return CollisionRules

Both groups still collide with Default, so walls, scrap and the crate stop players and the crawler as before. The crawler can still bite you: its attack is a distance check, not a bump.

Build along

m14-ship

  • src/server/CollisionRules.luau
  • src/server/init.server.luau
  1. Add CollisionRules.luau, require it in init.server.luau, and call CollisionRules.start() before CrawlerService starts so the first crawler's root is caught by the tag signal.

    You should see Window ⟩ 3D ⟩ Collision Groups during Play lists Default, Players and Crawler, with Players against Players and Players against Crawler unticked.

  2. Walk one player into the other, then into a wall.

    You should see In a Server & Clients test with 2 clients, the two characters walk through each other but not through the scrap stacks or the shop walls.

  3. Start a drill and stand still in the crawler's path.

    You should see During a drill the crawler walks straight through a player standing in its way, and still bites when it is within reach.

Open this step in lesson mode · Link to this step · This confused me

9Drag the crate, with the server's permission

A DragDetector makes a part draggable with a mouse, a finger or a gamepad, with no input code7. Put one in the exhibit crate. DragStyle TranslatePlane drags along the ground plane. ResponseStyle Physical moves an unanchored part with constraint forces, so the crate still slides, hits things and stops at the end of its 8-stud rope.

Who may drag is a server decision. With RunLocally false, the default, the client only sends its input and the server performs the drag, and any permission or constraint function must live in a server script. Set PermissionPolicy to Scriptable and register a function that gets the player and returns true or false.

luau
-- in ExhibitService, after the crate and its rope exist
local REACH = 12
 
local drag = Instance.new("DragDetector")
drag.DragStyle = Enum.DragDetectorDragStyle.TranslatePlane
drag.ResponseStyle = Enum.DragDetectorResponseStyle.Physical
drag.PermissionPolicy = Enum.DragDetectorPermissionPolicy.Scriptable
drag:SetPermissionPolicyFunction(function(player: Player, _part: BasePart?)
	local character = player.Character
	local root = if character then character:FindFirstChild("HumanoidRootPart") else nil
	if root == nil or not root:IsA("BasePart") then
		return false
	end
	return (root.Position - crate.Position).Magnitude <= REACH
end)
drag.Parent = crate

Build along

m14-ship

  • src/server/ExhibitService.luau
  1. Add the block to ExhibitService.start, run rojo serve, press Play and drag the crate.

    You should see Standing by the crate, you can drag it across the ground; it stops when the rope is straight and bumps into the hitch post.

  2. Walk away and try again.

    You should see From more than 12 studs away the crate does not move when you drag it.

  3. Run a Server & Clients test with 2 clients and drag from each one in turn.

    You should see A second client can drag the crate too, and both see the same motion.

To make dragging feel snappier, someone sets drag.RunLocally = true and keeps the permission function in ExhibitService. What happens?

drag.RunLocally = true
  1. The server never hears about the drag, so its permission function no longer decides anything
  2. Nothing changes; the server still checks the distance
  3. The crate becomes anchored
  4. Only players within 12 studs can drag, checked twice
Answer

The server never hears about the drag, so its permission function no longer decides anything. RunLocally true keeps the drag on the client. Permission checks then live in client scripts and changes must be sent to the server by remotes, which brings back every validation problem remotes have. Keep it false for anything that matters.

Open this step in lesson mode · Link to this step · This confused me

10Challenges

Level 1, Apprentice

Challenge

Turn the sign into a self-closing door with a servo, then restore it.

Start from
The game at milestone m06 (download)

Done means

  • With ActuatorType Servo and TargetAngle 0, the sign swings back to the middle after a push
  • ActuatorType is None again afterwards

Hints

  1. Servo needs ServoMaxTorque large enough to move the sign, and an AngularSpeed above zero.
  2. Change it on the server in Play to try values quickly, then put the code back.

You want a turnstile that keeps spinning slowly forever. Which ActuatorType?

  1. Motor
  2. Servo
  3. None
  4. Rope
Answer

Motor. Motor drives toward an angular velocity, so it keeps turning. Servo drives toward an angle and stops there. Rope is not an actuator type.

Level 2, Builder

Challenge

Watch ownership move between two clients, then pin the crate to the server.

Start from
The game at milestone m06 (download)

Done means

  • In a two-client Server & Clients playtest, the crate's owner changes as players walk up to it
  • After adding crate:SetNetworkOwner(nil) on the server, it stays with the server
  • The call is removed again afterwards

Hints

  1. Open the viewport's Visualization Options and turn on Network owners to colour parts by owner.
  2. Call SetNetworkOwner only on the server, after the crate is in Workspace.

Level 3, Professional

Challenge

Add a second rope between two anchored pegs.

Start from
The game at milestone m06 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("physics", "physics-guide-rope") in the server command bar. Copy the pass code from Output.

Done means

  • A RopeConstraint named GuideRope, Length 4, Visible = true, exists under Workspace.Yard.PhysicsExhibit
  • Both of its attachments are on anchored BaseParts
  • GuideRope is added as a separate RopeConstraint (do not rename CrateRope)
  • challenges/physics.luau prints TEST PASS guide_rope

Hints

  1. ExhibitService already has part and pointAttachment helpers.
  2. Put two thin anchored pegs 4 studs apart and tie them.

Open this step in lesson mode · Link to this step · This confused me

11Recap

Retiring the analogy

You no longer need “whoever holds the ball”. Each unanchored assembly is simulated by one machine. Clients near it usually own it for responsiveness; their simulated positions replicate to the server. Anything gameplay-critical is anchored or kept server-owned, and the server validates results instead of trusting the owner.

Recap

  1. Constraints join attachments: a hinge rotates around Attachment0's X axis (None, Motor or Servo), a rope is a maximum distance, a weld fixes two parts together.
  2. Welded parts form one assembly that moves and weighs as one; Massless and query-off keep decorative meshes out of gameplay.
  3. Unanchored parts are simulated by a nearby client by default; anything that decides gameplay is anchored or kept on the server with SetNetworkOwner(nil).
  4. Collision groups decide which solid parts block each other (register them on workspace, not PhysicsService); a DragDetector with RunLocally off lets the server decide who may drag.

Network ownership is whoever holds the ball, until the server can take the ball back at any time and always keeps anchored parts, and the holder is trusted with positions it reports, so a cheating holder can move the ball anywhere.

Next Players, characters, teams and chat

Open this step in lesson mode · Link to this step · This confused me