# joints

Part of the [scripting reference](index.md), written by the engine so it matches your `frost`. Start with [your first game](../start/first-game.md) if you are new.

Use when connecting bodies with joints, building wheels, vehicles, ropes, hinges or 3D constraints.

| In a script | Does |
| --- | --- |
| `physics.wheels(car)` | A `Vehicle`'s four wheels, front left, front right, back left, back right, each `{ x, y, z, qx, qy, qz, qw, touching }` (its axle is its own x), or nil for no car |

| Component | Field | Type | Default | Meaning |
| --- | --- | --- | --- | --- |
| `Joint` | `kind` | text | `"revolute"` | `"distance"`: a rod, or a spring or a rope, between two points. `"revolute"`: a hinge. `"prismatic"`: a slider along a line, which does not turn. `"weld"`: stuck together. `"wheel"`: a wheel that spins freely on an axle that slides along a line |
| `Joint` | `from` | text | `""` | The name of the entity the joint holds. Empty: the entity the `Joint` is on. An entity can be nothing but a joint between two others, which is how one body gets several |
| `Joint` | `to` | text | `""` | The name of the entity it is joined to. Empty: the world |
| `Joint` | `x` | number | 0 | Where the joint holds the `from` entity, from its `Transform`, turning with it |
| `Joint` | `y` | number | 0 | The same upwards |
| `Joint` | `to_x` | number | 0 | A distance joint only: where it holds the `to` entity, from that entity's `Transform` (from 0, 0 of the world when `to` is empty). The other kinds hold the `to` entity where the `from` entity's point is when the joint is made |
| `Joint` | `to_y` | number | 0 | The same upwards |
| `Joint` | `angle` | number | 0 | The direction of a slider's or a wheel axle's line, in degrees, turning with the `to` entity: 0 to the right, 90 up |
| `Joint` | `length` | number | 0 | A distance joint's length. 0: as far apart as its two points are when it is made |
| `Joint` | `limit` | true or false | false | Whether `min` and `max` hold |
| `Joint` | `min` | number | 0 | The least a hinge turns (degrees), a slider or an axle moves along its line, or a distance joint's length is (units). Turning and moving count from how the two were when the joint was made |
| `Joint` | `max` | number | 0 | The most |
| `Joint` | `speed` | number | 0 | The speed its motor drives at: degrees a second for a hinge or a wheel, units a second for a slider or a distance joint |
| `Joint` | `power` | number | 0 | The most the motor can do to get there. 0: no motor. A force (a mass times units a second squared) for a slider or a distance joint, a turning force (that times units) for a hinge or a wheel; a body's mass is its area in square metres times its density. A motor far stronger than its load pushes a little past `limit` (500 N·m on a door of 0.2 kg: 7.5° in 3D, 11.6° in 2D) |
| `Joint` | `spring` | number | 0 | Springiness, in swings a second. 0: rigid (a slider and a hinge then have no spring; a weld and a rod do not give). For a wheel it is the axle's suspension: at 0 the axle is rigid, held where it was made, unless `limit` gives it a range to slide in. For a hinge it is a spring towards how it was made |
| `Joint` | `damping` | number | 0 | How quickly the spring stops swinging: 0 never, 1 without a swing |
| `Joint` | `collide` | true or false | false | Whether the two joined bodies still collide with each other |
| `Vehicle` | `forward` | number | 0 | The throttle, -1 (backwards) to 1. Asked the other way while it rolls, it brakes first |
| `Vehicle` | `right` | number | 0 | Steering, -1 (left) to 1: that share of `steer` |
| `Vehicle` | `brake` | number | 0 | The brakes on all four wheels, 0 to 1 |
| `Vehicle` | `handbrake` | number | 0 | The handbrake, on the back wheels, 0 to 1 |
| `Vehicle` | `speed` | number | 0 | Written by the engine: units a second along its front, negative backwards |
| `Vehicle` | `revs` | number | 0 | Written: the engine's revolutions a minute |
| `Vehicle` | `gear` | whole number | 0 | Written: -1 reverse, 0 none, 1 to 5 |
| `Vehicle` | `touching` | whole number | 0 | Written: how many wheels are on something |
| `Vehicle` | `wheel`, `width`, `track`, `front`, `back`, `hang`, `travel`, `spring`, `damping`, `steer`, `drive`, `torque`, `rpm`, `brakes`, `handbrakes` | number, `drive` text | 0.3, 0.2, 1.6, 1.25, -1.25, -0.2, 0.2, 1.5, 0.5, 35, `"front"`, 500, 6000, 1500, 4000 | What it is made of, in its own frame, never scaled with the thing (changing one makes it again): a wheel's radius and width; from the left wheels to the right; the front and back axles' z; a wheel's middle y with its spring in, and how far it hangs below that; the springs' swings a second and damping; the most it steers, in degrees; the driven wheels, `"front"`, `"back"` or `"all"`; the engine's most turning force (a mass times units squared a second squared) and revolutions a minute; the most the brakes and the handbrake do |

- **Joints.** A `Joint` joins `from` to `to`: put it on the entity it holds and name the
  other, or, for a second joint on the same body (a chain, a bridge fixed at both
  ends), on an entity of its own that names both. Both ends need a `Collider`, and
  neither is a `Mover`. It is made where the two are when both have
  bodies, and made again from where they are then when a `Collider`, a `Body.kind` or
  any of its own fields but `speed` and `power` changes: those two a script writes
  freely, to drive a motor, without its limits moving. When either end is despawned
  the joint goes with it: the `Joint` is taken off its entity and the game is told
  once, as a warning (`W1112`).

- **A car.** In a 3D game a `Vehicle` beside a `Collider` and a dynamic `Body` is a car,
  its front its own +z: its wheels are the physics' own, on springs, with an engine and
  gears. The defaults fit a `Collider` of 1.8 by 0.6 by 4 at `density` 280, in metres. A
  script drives it by `forward`, `right`, `brake` and `handbrake`, and draws its wheels
  where `physics.wheels(car)` says. Anything else stops the load or the step with what
  to do: a 2D game (`E0459`), a body that is not dynamic (`E0460`), no `Collider`
  (`E0461`), a field no car has (`E0462`).
