Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 37 ยท Parts, Physics and Building

Anchoring, Collisions and Physics

"Understand Roblox physics: Anchored and CanCollide, gravity, mass and velocity, WeldConstraint and hinges, collision groups, and how to make parts move without fighting the engine."

Roblox has a built-in physics engine. Unanchored parts fall, bounce, slide and tumble without any code from you. That is wonderful for ragdolls and rolling boulders, and a surprise if you only wanted a floating platform. This lesson explains the properties that control physics and the tools to join and steer parts.

Anchored: fixed or free

Anchored = true pins a part in space. The physics engine never moves it, and nothing can push it, but you can still move it from a script by changing Position or CFrame.

Anchored = false (the default for a new part) hands the part to physics: gravity pulls it down until it rests on something.

Rules of thumb:

  • Anchor floors, walls, platforms, decorations and anything you move by script.
  • Unanchor objects that should react to the world: balls, crates, ragdolls, vehicles.
  • A model of many parts should be either anchored all together, or held together with welds (below), or its parts fall apart.

Test it in a Script:

LUA
local ball = Instance.new("Part")
ball.Shape = Enum.PartType.Ball
ball.Size = Vector3.new(4, 4, 4)
ball.Position = Vector3.new(0, 50, 0)
ball.Anchored = false           -- gravity applies; it falls
ball.Parent = workspace

CanCollide, CanTouch and CanQuery

Three switches decide how a part interacts with others:

Property If false
CanCollide Other parts pass through it; no physical bump
CanTouch Touched and TouchEnded events do not fire for it
CanQuery Raycasts and spatial queries ignore it

A ghost wall: CanCollide = false, Transparency = 0.7. A trigger zone (a pad that detects players but lets them walk through): CanCollide = false, Anchored = true, CanTouch = true. Switching off unneeded checks on decorative parts saves performance.

Gravity, mass and velocity

The world's gravity is a property of Workspace, measured in studs per second squared. The default is 196.2, about 9.8 m/s squared on the Roblox scale (1 stud is about 0.28 m).

LUA
workspace.Gravity = 196.2    -- default
workspace.Gravity = 50       -- floaty, moon-like

Each part has mass (part.Mass, read-only), computed from its size and material density. You can override physical properties:

LUA
part.CustomPhysicalProperties = PhysicalProperties.new(
	0.7,   -- density
	0.3,   -- friction
	0.5,   -- elasticity (bounciness)
	1,     -- friction weight
	1      -- elasticity weight
)

Move a free part with velocity:

LUA
part.AssemblyLinearVelocity = Vector3.new(0, 50, 0)    -- shoot it upward
part.AssemblyAngularVelocity = Vector3.new(0, 5, 0)    -- spin it
part:ApplyImpulse(Vector3.new(0, 1000, 0))              -- a one-time push

Modern physics uses assemblies: a group of unanchored parts connected by joints is one rigid unit, with a single velocity and centre of mass.

Joining parts

Unanchored parts that are not joined fall independently. To make a rigid object, weld them:

LUA
local weld = Instance.new("WeldConstraint")
weld.Part0 = body
weld.Part1 = wheel
weld.Parent = body

A WeldConstraint keeps two parts at the same relative position forever, wherever they are moved. Other constraints give controlled motion:

  • HingeConstraint: a door, a wheel, a propeller (rotation around an axis, can have a motor).
  • PrismaticConstraint (also SliderConstraint): a sliding drawer or lift.
  • BallSocketConstraint: a ragdoll joint.
  • SpringConstraint and RopeConstraint: bouncy and tied connections.

In Studio you can create them from the Model tab's constraint tools without code.

Collision groups

Sometimes certain parts should ignore each other: players should pass through their own team's barrier, or bullets should not hit the shooter. Collision groups control this:

LUA
local PhysicsService = game:GetService("PhysicsService")

PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("Ghosts")
PhysicsService:CollisionGroupSetCollidable("Players", "Ghosts", false)

part.CollisionGroup = "Ghosts"

Now parts in Ghosts do not collide with parts in Players, but still collide with everything else.

Network ownership

For smooth gameplay, the server lets the nearest player's client simulate unanchored parts that player is touching or driving. This is network ownership. It keeps the controls responsive but means that client-simulated physics can be cheated. If a part must be fully trustworthy (such as a gem that gives rewards), anchor it, or take control with part:SetNetworkOwner(nil), which gives ownership to the server.

Stand-in: gravity and a bounce

Physics needs the engine, but the maths is just numbers changing over time. This JavaScript stand-in simulates a falling, bouncing ball using a fixed time step: gravity changes velocity, velocity changes position, and the ground reverses (and reduces) the velocity. Change gravity, elasticity or the anchored flag.

JS Stand-in: gravity, bounce and Anchored (JavaScript)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The free ball falls, bounces lower each time (elasticity below 1 loses energy), and settles. The anchored ball never changes, exactly like a part with Anchored = true.

Stand-in: a collision group table

Collision groups are a table of "who collides with whom". This stand-in models the rule (defaulting to colliding) and answers questions about pairs.

JS Stand-in: collision groups (JavaScript)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Troubleshooting

  • My platform falls when I press Play. It is not anchored.
  • My model collapses into pieces. Weld its parts or anchor them all.
  • A script-moved part jitters. Anchor it, or move it with a constraint instead of setting its CFrame every frame.
  • Players walk through my wall. CanCollide is off, or a collision group excludes them.
  • Touched never fires. CanTouch is off, or neither part is moving or unanchored (see the next lesson).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Anchored = true do?

    Anchored parts never move from physics, though scripts can still move them.
  2. 2. Which property stops other parts from bumping into a part?

    CanCollide = false lets other parts pass through; true makes it solid.
  3. 3. What keeps two unanchored parts together?

    A WeldConstraint fixes the relative position of two parts.
  4. 4. Which tool lets certain groups of parts ignore each other?

    Collision groups, set up with PhysicsService, decide which groups collide.

Summary

  • Anchor fixed things; leave dynamic things unanchored; weld multi-part objects.
  • CanCollide, CanTouch and CanQuery control bumping, events and raycasts.
  • Gravity, mass, velocity and PhysicalProperties shape movement; constraints make hinges, springs and slides.
  • Collision groups filter which parts collide; network ownership decides who simulates a part.

Next: Touched Events and Hazards