Joints in R3: hinges, sliders and welds, by hand
Connect two physics objects with a joint in the R3 Inspector: a pendulum, a hinge that stops at 45 degrees, a motor, a slider on a rail and a weld. No code, no AI.
A title card reads "How to connect objects with a joint". In the R3 editor a small grey cube, the hook, hangs in the air above a grey floor, and a blue cube, the weight, sits two metres to its right. The cursor opens Create and adds a Joint Revolute. In the Inspector it opens Joints and the new joint, sets Body 1 to the hook and Body 2 to the weight, Anchor 2 X to -2 and the Axis to 0, 0, 1, every value circled and zoomed in. It presses Start Physics: the weight swings down and up the other side like a pendulum. It stops physics, ticks Limits Enabled and sets the angles to -0.785 and 0.785: started again, the weight swings down 45 degrees and stops. Then it unticks the limits and ticks Motor Enabled with a velocity of 3: the weight goes round and round the hook. An AI voice narrates. End card: r3js.org.
Transcript
0:02 A fixed hook, and a weight beside it. Open Create, and add a Joint Revolute, a hinge.
0:12 In the Inspector, open Joints, and the new joint. Body 1 is the hook. Body 2 is the weight.
0:23 The pivot, seen from the weight, is two metres to its left. The axis points at you, so it swings on the screen.
0:35 Start physics. A pendulum.
0:42 Now tick Limits Enabled, and stop it at 45 degrees each way. That's 0.785, in radians.
0:52 Start again. Now it stops, like a door.
0:57 Limits off, motor on, at three radians a second.
1:01 Start, and the motor turns it round and round.
A joint connects two physics bodies and decides how they may move against each other. It is the part list of a small machine: a hinge, a rail, a weld. R3 has four:
| Joint | Like | It lets body 2 |
|---|---|---|
| Joint Revolute | a hinge, an axle | turn around one line (the Axis), optionally between two angles, optionally driven by a motor |
| Joint Prismatic | a drawer, a rail | slide along one line (the Axis), optionally between two distances |
| Joint Fixed | a weld, glue | not move at all against body 1 |
| Joint Spherical | a ball joint, a shoulder | turn in every direction around one point |
You build everything below in the Inspector, by hand: no code, no AI. Each part takes a few minutes. (Want your AI to do it? See Joints in R3 with your AI.)
The words, once
- Body 1 and Body 2: the two rigid bodies the joint connects. Here Body 1 is always a fixed hook that never moves, and Body 2 is the part that moves.
- Anchor 1 and Anchor 2: the point where the two are joined, written twice: once measured from the centre of body 1, once from the centre of body 2. Both name the same point. They are in metres and in each body's own frame (if the body is turned, its x, y and z turn with it).
- Axis: the line a hinge turns around, or the direction a slider moves in, in body 1's frame. Give it a length of 1:
(0, 0, 1), or(0.7071, -0.7071, 0)for 45 degrees down. - The joint starts from where you put things. When you press Start Physics, the pose at that moment is the joint's zero: limits count from there.
- Limits are in radians for a hinge (180 degrees = 3.1416, so 45 degrees = 0.785) and in metres for a slider. Careful: the Inspector's Rotation fields are in degrees, the joint's angles are not.
- Stop Physics puts every body back where it started, so you can change a value and try again.
1. A ground and a hook
Every part below starts the same way.
- Open the Create menu and press Empty Project (in the Projects section). Then search for physics and add a Physics Plane (the ground) and a Physics Cube (the part that will move: its mesh is
mesh_physics_cube_1, its bodyrigidbody_physics_cube_1). - Search for cube and add a plain Cube: this is the hook. Then search for rigidbody fixed and add a RigidBody Fixed, and search for collider cuboid and add a Collider Cuboid. Close the menu.
- Open the Inspector. Open 3D Objects, then the Cube
mesh_cube_1: set its Position Y to 4 and its Scale to 0.5, 0.5, 0.5. The hook now hangs in the air. (Typing a name such asmesh_cube_1in the Inspector's search box finds any component quickly.) - Open Rigid Bodies, then
rigid_body_fixed_1, and set its Mesh tomesh_cube_1. Open Colliders, thencollider_cuboid_1, and set its Rigid Body torigid_body_fixed_1and its Mesh tomesh_cube_1.
The hook is now a fixed body at (0, 4, 0): physics will never move it. A fixed body is what you hang things from.
2. A pendulum: Joint Revolute
- Open the Physics Cube
mesh_physics_cube_1(also under 3D Objects) and set its Position to X 2, Y 4: two metres to the right of the hook. - Open the Create menu, search for joint revolute and add a Joint Revolute. Close the menu.
- In the Inspector, open Joints, then
joint_revolute_1. Its fields sit in folded sections: open Bodies and Anchors.
- Body 1: rigid_body_fixed_1 (the hook). Body 2: rigidbody_physics_cube_1 (the weight). - Anchor 1 stays 0, 0, 0: the pivot is the hook's centre. - Anchor 2 X: -2. The same pivot, seen from the weight: two metres to its left. - Axis: X 0, Y 0, Z 1. The weight turns around the line that points at you, so it swings left and right on the screen.
- Start Physics (the play button next to Physics at the top).
The weight falls, swings down through the bottom and up the other side, again and again, always two metres from the hook. That is a pendulum. Stop Physics when you have seen enough: everything goes back to its start.
3. A hinge that stops: limits
A door does not swing all the way round. Give the same joint limits:
- In
joint_revolute_1, open the Limits section and tick Limits Enabled. - Set Min Angle to -0.785 and Max Angle to 0.785: 45 degrees each way, in radians, counted from where the weight starts.
- Start Physics.
The weight now swings down only 45 degrees and stops there, as if it hit a door stop. Stop Physics, change the angles and start again to try other stops.
4. A motor
A motor turns the hinge by itself, like a wheel on an axle.
- In
joint_revolute_1, untick Limits Enabled (a limit would stop the motor too). - Open the Motor section, tick Motor Enabled and set Motor Velocity to 3: three radians a second, about half a turn a second. Motor Max Force is how hard it may push: the default 1000 lifts this cube over the top easily; a heavier part needs more.
- Start Physics.
The weight goes round and round the hook, over the top. A negative velocity turns it the other way. Untick Motor Enabled and it is a free pendulum again.
5. A slider: Joint Prismatic
Start a new project with a ground, a hook and a Physics Cube (part 1). Then:
- Set the Physics Cube's Position to X 2, Y 4.
- Add a Joint Prismatic (Create menu, search joint prismatic). In the Inspector, open Joints, then
joint_prismatic_1, and its Bodies, Anchors and Limits sections:
- Body 1: the hook rigid_body_fixed_1. Body 2: rigidbody_physics_cube_1. - Anchor 1 X: 2: the rail passes through the cube's centre, two metres right of the hook. Anchor 2 stays 0, 0, 0 (the cube's own centre: the same point). - Axis: X 0.7071, Y -0.7071, Z 0: the rail goes down and to the right, at 45 degrees. - Tick Limits Enabled, and set Min Distance to 0 and Max Distance to 1.5: the cube may move from where it starts to 1.5 metres down the rail.
- Start Physics.
The cube slides down its slanted rail, without turning and without leaving the line, and stops 1.5 metres along. A drawer is the same joint with a level axis (1, 0, 0). A slider has no motor in R3: push it from code, or tilt its rail.
6. A weld: Joint Fixed
A fixed joint glues two bodies together, so they move as one: a handle on a door, a ramp on a cart, a part at an angle.
Start a new project with a ground, a hook and a Physics Cube (part 1). Then:
- Set the Physics Cube's Position to X 1.2, Y 4, and its Rotation Z to 30 (degrees, in the Inspector): it sits right next to the hook, tilted.
- Add a Joint Fixed (Create menu, search joint fixed). In the Inspector, open Joints, then
joint_fixed_1, and its Bodies and Anchors sections:
- Body 1: rigid_body_fixed_1. Body 2: rigidbody_physics_cube_1. - Anchor 1 X: 1.2: the weld point is the cube's centre, 1.2 metres right of the hook. Anchor 2 stays 0, 0, 0.
- Start Physics.
The cube does not fall: it stays exactly where you put it, still tilted 30 degrees, held by the hook. Clear Body 2 and start again, and it drops to the ground. Weld two Physics Cubes to each other (Body 1 and Body 2 both dynamic) and the pair falls and tumbles as one piece.
7. And a ball joint: Joint Spherical
A Joint Spherical is set up like the pendulum (Body 1 the hook, Body 2 the weight, Anchor 2 X -2) but has no axis: the weight can swing in every direction around the hook, like a ball on a string. Give the weight a sideways push (its rigid body's Linear Velocity Z = 3) and it swings in a circle in 3D. It has no limits and no motor.
When it does not move
- Nothing happens at Start. Check that Body 1 and Body 2 are both set. A joint with only one body does nothing (the browser's console, F12, says
requires two valid rigid bodies). - The part jumps at Start. The two anchors do not name the same point. Measure again: Anchor 1 from the centre of body 1, Anchor 2 from the centre of body 2.
- The pendulum swings the wrong way (towards or away from you). The Axis is wrong:
(0, 0, 1)swings left and right on screen,(1, 0, 0)towards and away from you. - The Inspector will not let you change a value. While physics runs it is locked ("Physics is running — Stop to edit"): press Stop, change the value, and start Physics again.
- A motor barely moves. Raise Motor Max Force.
R3 has no spring, rope or distance joint, and no motor on a slider. The full reference for every option is in the API reference: open it, then Joint Revolute, Joint Prismatic, Joint Fixed or Joint Spherical. For physics in general (bodies, colliders, gravity), see Physics in R3.