Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

WheelCollider

A wheel of a ray-cast vehicle (Unity-style). Add it to a child entity of a rigid body: every wheel under one body is one wheel of that body's vehicle, simulated by rapier's ray-cast vehicle controller (DynamicRayCastVehicleController). The system finds the nearest ancestor with a Physics component and drives it.

Each physics tick a wheel casts its suspension ray straight down the chassis' local -Y from its own position, which is the suspension mount. The ray passes through triggers and through the chassis' own colliders, so a chassis BoxCollider around the mounts is fine. The wheel stands on the nearest surface along the ray whose normal faces back along it within groundAngle (45 degrees by default); the ray reads past a steeper face, such as the side of a crate, a kerb's face or a wall, to the ground beyond it, so a wheel meets a box on the road on its top. The controller then applies the suspension, drive, brake and tyre grip to the chassis as impulses, and the opposite of each, at the tyre's contact, to the dynamic body the wheel stands on: a car parked on a deck, a seesaw, a soft body or another car weighs on it as the same chassis resting on it directly does, and a car that drives or brakes on a floating deck pushes the deck the other way, the two sharing one momentum. The push into that body reaches it whole where its contacts hold it up, as a deck or a crate lying on the floor is held, and where it would throw a light body out from under the tyre, or tip it about the edge it stands on, it reaches the body only as far as the tyre can follow it, the spring's compression over a tick, and the body pushes the chassis back no harder than that. Along the ground, the drive, brake and grip push the body as far as its own movement was counted when they were sized: a car on its own wheels or a deck on ice takes the whole push and moves under it, while a crate the floor's friction holds passes it on to the floor. The fixed world carries whatever the body does not take.

Drive conventions: positive motorTorque drives toward the parent body's local -Z (the engine's forward); positive steerAngle steers right.

Fields

FieldMeaning
suspensionDistanceSuspension travel (m): the wheel hangs at most this far below the mount, and the spring compresses by at most this much from its rest, where the bump stop holds the wheel.
targetPositionWhere the spring rests, as a share of suspensionDistance below the mount. The spring's rest length is suspensionDistance * targetPosition, and the wheel reaches the ground within that length plus its radius. 1 rests at full extension. The spring compresses from its rest by up to suspensionDistance, where the bump stop is.
springRate, damperRateSpring stiffness (N/m) and damping (N·s/m) per wheel.
maxSuspensionForceThe most force (N) one wheel's suspension pushes with (default 6000). Raise it for a vehicle heavier than about 2 t on four wheels.
bumpStopRecovery, bumpStopSpeedHow the bump stop pushes a chassis standing past it back out: by bumpStopRecovery of the depth each physics tick (default 0.2), and no faster than bumpStopSpeed (m/s, default 1).
groundAngleThe steepest surface the wheel stands on (degrees, default 45): the widest angle between a surface's normal and the suspension, pointing back up it. The ray reads past a steeper face to the ground beyond it. A wheel at 60 climbs a 50 degree face that a default wheel reads past (a rock crawler, a kart riding kerbs, a bogie on a ramp); one at 30 stands only on gentle ground.
radius, widthWheel size (m). An unset radius comes from the wheel entity's model bounds, or else from its visual's. The ray is cast from the centre of the tread, so a chassis leaning over flat ground meets it at the same points at any lean. It is cast from a shoulder instead when the ground under that shoulder stands more than 1 mm above the ground under the centre, so a kerb or a plank under one shoulder holds the wheel up, or when the centre finds no ground.
motorTorqueDrive torque (N·m). A wheel with no inertia drives with motorTorque / radius newtons, up to forwardFriction times the load it carries; a wheel that spins on its own takes it on its axle (see Spin below).
maxDriveSpeedThe tread speed (m/s, default 0) up to which motorTorque drives a wheel that spins on its own: below it the wheel takes the whole torque, and from it on only what holds its tread there, on the ground and in the air, the way a rev limit holds an engine. A reverse drive is held to it backward. 0 drives the wheel at any speed. It bounds what the drive does: a gripping tyre turns its wheel at the speed the road passes under it, so a car rolling faster than the top (down a hill, or its rear end lifting over a crest) turns its wheels faster than it while its drive puts nothing on them. A wheel with no inertia rolls at the road speed and its drive is held by its grip alone.
brakeTorqueBrake torque (N·m). A wheel with no inertia brakes with up to forwardFriction times the load, while motorTorque is 0, and so does rollingResistance; a wheel that spins on its own takes it on its axle, beside the drive. A braked car stands still on any slope its brakes' grip holds, gravity included.
steerAngleSteering angle (degrees), positive steers right. At light throttle the car turns on the radius its geometry gives, the wheelbase over tan(steerAngle), as long as the turn asks less of its tyres than their sideways grip (sidewaysFriction); driving the steered wheels hard tightens the turn and driving only the others widens it.
frictionSlipThe tyre's combined grip limit (default 10.5): the drive, brake and side grip together reach at most the suspension load times this before the tyre slides sideways. Lower it (1 or less) for ice, a drift car or skids.
sideFrictionStiffnessThe tyre's cornering stiffness (default 1): how hard it pushes back across its contact for each radian its contact slips off the line it rolls along, as a share of corneringStiffness times the load it carries. A standing tyre holds its contact still across the ground, so a chassis leaning on its springs or tipping over turns about its tyres' contacts; a rolling one answers a steady push across it with a steady slip angle, about 6 degrees at its sideways grip at the defaults.
corneringStiffnessThe base cornering stiffness (default 10): the sideways force, per newton of load, per radian of slip angle, that sideFrictionStiffness scales. At 10 and a sidewaysFriction of 1 the tyre's grip across the road peaks at about 6 degrees of slip angle; at 25 at about 2.3 degrees (a stiff race tyre), at 5 at about 11 (a soft, balloon or off-road tyre).
forwardFrictionLongitudinal grip coefficient (default 1): drive and brake force are held to this times the load the wheel carries.
inertiaThe wheel's moment of inertia about its axle (kg·m², default 0). Above 0 the wheel spins on its own (see Spin below); about half the wheel's mass times its radius squared, 1 to 2 for a car wheel. 0 rolls it at the road speed.
forwardFrictionStiffnessSlip-ratio stiffness of a wheel that spins on its own (default 1): how hard its tyre pushes along the road per unit of slip ratio, as a share of 10 times the load it carries. At the defaults its force reaches its load at a slip ratio of 0.1.
slideGripThe share of its grip a tyre of a wheel that spins on its own keeps once it slides (default 0.75): up to its peak slip it grips with all of forwardFriction and sidewaysFriction, and from slideSlip times that slip on with this share of them.
slideSlipWhere a tyre's grip curve has fallen off, for a wheel that spins on its own (default 2): the slip, as a multiple of its peak slip, at which its grip has fallen in a straight line from its peak to slideGrip of it. 1 lets go at once past the peak (a peaky tyre); 3 to 5 falls off gently and holds a slide. See Grip curve below.
loadSensitivity, referenceLoadTyre load sensitivity (default 0): every grip coefficient and stiffness of the tyre is scaled by (load / referenceLoad) ^ -loadSensitivity, so its grip per newton falls as its load rises, and at referenceLoad (N, default 4000) it grips with its coefficients as stated. 0 grips in proportion to load; 0.1 to 0.3 is a road tyre. Held to 0..0.9. See Grip curve below.
sidewaysFrictionSideways grip coefficient (default 1): the force the tyre pushes back with as the chassis moves across its contact, in a turn or under a push from the side, reaches at most this times the load it carries, less what its drive or brake spends of it. A car turning harder than that slides wide: steered 10 degrees, a 2 t truck turns on the 19 m its steering gives at 5 m/s and slides wide on its wheels at 20 m/s. Gravity's pull across a slope is held by the tyre's combined grip, frictionSlip, so a truck standing across a slope stays where it stands until it tips.
rollingResistanceDrag on a freely rolling wheel, times the load it carries. The ground under the tyre adds its own rollingResistance (see Ground below).
surfaceGripHow this tyre grips particular ground: { { surface = "ice", grip = 0.35 }, { surface = "loose", grip = 0.8 } }. On a surface an entry names, by its name or one of its tags, the tyre grips with grip of its stated grip in place of the surface's friction: a studded tyre on ice, an off-road tread on gravel. The surface's own name is matched first, then its tags in their order. Empty by default.
is2DThe wheel applies no sideways grip.
visualThe wheel's visual: an entity, or its id (see below).
solidThe wheel is a volume other bodies strike (default false): see Solid wheels below.
massThe wheel's mass (kg, default 20) as a body of its own once it comes off.
breakLoadThe force (N) above which the wheel comes off its vehicle (default 0, never): see Wheels that come off below.
attachedWhether the wheel is on its vehicle (default true). Set false to take it off, true to put it back on its mount.
detachReasonWhy the wheel came off: "load" or "command"; empty while it is on.

The suspension ends at a bump stop: once the spring has compressed by suspensionDistance from its rest, the wheel holds the chassis off the ground there like a solid contact. It stops the chassis closing on the ground within the tick, so a landing faster than the springs can take, or a chassis heavier than its springs carry, ends on the stops with the tyre on the ground rather than in it, and the chassis is not thrown back up. A chassis that stands past its stops (put there by a script, say) is eased back out by bumpStopRecovery of the depth each tick, at no more than bumpStopSpeed (1 m/s by default).

The spring is applied as an impulse worked out from the state at the start of each tick. So that it cannot feed on itself, its rate is held, per tick, to what the chassis' mass and its rotational inertia integrate stably: a light chassis, or one whose pitch or roll inertia is small next to its wheelbase, gets less of a very stiff spring than authored. The damper is applied to the velocity the chassis ends the tick with, which is stable at any rate, so the authored damperRate always acts whole. A damper pulls a wheel down no harder than its spring pushes it.

Ground

A tyre's grip coefficients (forwardFriction, sidewaysFriction, frictionSlip) are stated for ground of friction 1. On a surface content defined (Physics.defineSurface), named by the collider under the tyre or painted on a Terrain under it, every one of them is scaled by the surface's friction, or by the tyre's own surfaceGrip entry for that surface; its stiffnesses are not, so on slippery ground the tyre reaches its lower peak at a smaller slip. The ground's rollingResistance adds to the tyre's own: the surface's, or the collider's own on a collider naming none. So one car on tarmac, gravel, grass and ice brakes, accelerates and corners differently with no script, wheel by wheel: a car with its left wheels on ice and its right on tarmac pulls right under the brake. Ground naming no defined surface leaves the tyre's grip coefficients as stated, whatever the collider's own friction. A surface defined without a friction takes 0.5, so a tyre grips it with half its stated grip: state friction = 1 for ground a tyre grips as stated (dry tarmac), and lower for looser ground, for example Physics.defineSurface("tarmac", { friction = 1.0, rollingResistance = 0.01 }), "gravel" 0.6, "grass" 0.45, "ice" 0.1. surface and ground in the runtime state name what each tyre stands on, and Physics.tyreCurve(wheelId, { surface = "gravel" }) measures the curve on a given surface.

Runtime state

Read-only, updated every physics tick, and readable through Physics.getWheelState(wheelId):

  • isGrounded: the tyre touches the ground anywhere within the suspension's full travel, suspensionDistance below the mount. Past the spring's rest it carries no load.
  • compression (0 with the spring at or past its rest length, up to suspensionDistance, where the bump stop is).
  • angularVelocity (rad/s) and rotation (rad): the wheel's spin and its angle about the axle, both growing as it rolls forward. A wheel with no inertia turns by the distance rolled over the radius; one that spins on its own turns at its own spin.
  • skid (m/s): how fast the tyre slides while its grip is used up; 0 while the tyre holds. Sideways for a wheel with no inertia; along the road too for one that spins on its own, so a locked or spinning tyre reads its slide.
  • slipRatio: the tread's speed less the road's under it, both positive rolling forward, as a share of the road speed (taken as at least 0.5 m/s), so its sign is the way the tyre pushes the car along the road. Rolling forward it reads 0 rolling, above 0 in wheelspin (1 at twice the road speed) and -1 locked; rolling backward the signs turn over, a wheel spinning backward past the road reading below 0 and a locked one 1. 0 for a wheel with no inertia.
  • slipAngle (degrees): the angle between the line the tyre rolls along and the way its contact moves over the ground, positive as the contact moves toward the wheel's right: how far into a drift the tyre is.
  • roadSpeed (m/s): how fast the ground passes under the tyre along the line it rolls along, positive rolling forward. load (N): the force the tyre presses the ground with, which its grip is sized by.
  • sideImpulse, forwardImpulse (N·s): what the tyre applied to the chassis this tick, and sideForce, forwardForce (N) the same over the tick. suspensionForce (N). stopImpulse (N·s): what the bump stop applied this tick, the part of a landing or a load the suspension could not take.
  • center, hitPoint, hitNormal: the wheel centre and the ground contact, in world space. A wheel with no ground within its travel hangs at full travel.
  • surface: the surface the tyre touches (Physics.defineSurface), the one the collider under it names there or, on a painted Terrain, the layer under the contact; absent on ground naming none. ground: the entity id of what it touches. Both are also on the component (wheel.component.get("WheelCollider").surface).
  • reaction (N): the force the ground and whatever struck the wheel's volume put on the wheel in the last tick: the suspension's push, the bump stop's, the tyre's along and across the road, and the contacts on its volume, their push and their friction, added as vectors. What breakLoad is measured against. detachLoad (N): the reaction the wheel came off at, 0 for one taken off by command.
  • vehicleOrder: the wheel's place among the wheels of its vehicle, from 1: the order the vehicle steps them in, which is the order they arrived in the world, and the order Physics.vehicleState lists them in. A wheel that came off keeps the place it last held; one that has not stepped on a vehicle reads 0.

Drivetrains. An engine, a clutch, a gearbox and a differential driving the wheels are a ShaftNetwork (on the chassis, say) whose parts name the wheels: { name = "rearLeft", wheel = rl }. A wheel a network drives spins on its own (with its own inertia, or the part's when it states none), its motorTorque (up to maxDriveSpeed) and brakeTorque still acting on its axle, and the network's links (a shaft, a gear ratio, a clutch, an open, locked or limited-slip differential) are solved with the tyres and the chassis in one step: one wheel on ice spins behind an open differential while the other stands, and a locked one drives both. The ShaftNetwork component README has the fields, and the physics guide (topics/physics) a car recipe.

A driver for the wheels is built in: VehicleController on the chassis reads the vehicle input map, or the intent code gives it through setIntent (an AI driver, a replay, a test), and writes motorTorque, brakeTorque and steerAngle.

Physics.vehicleState(chassisId) reads the whole vehicle: the chassis' forward speed (m/s, negative in reverse), how many wheels are grounded, and each wheel's state, in the order the vehicle steps its wheels. That order is the order the wheels arrived in the world (the first spawned first), and each wheel's place in it is its vehicleOrder (from 1). The vehicle steps its wheels in that order on every run and every engine, whatever entity slots the wheels were given, so a car stepped the same steps from the same state reads the same Physics.stateDigest.

Spin: wheelspin, lock-up and drifts

A wheel with an inertia above 0 spins on its own. Its spin is integrated each tick from the torques on its axle: motorTorque drives it, brakeTorque (with rollingResistance times its load) holds it toward still, and its tyre pushes back. The tyre pushes the chassis along the road in proportion to the slip between its tread and the road (the slip ratio, forwardFrictionStiffness), up to forwardFriction times its load; the wheel and the chassis are solved together, so it is stable at the engine's 30 Hz and 60 Hz ticks with a wheel however light. So:

  • Wheelspin. A drive torque past what the tyre puts down spins the wheel up faster than the road (slipRatio above 0), and the car gains speed only as fast as its grip pushes it: 250 N·m on each wheel of a 600 kg car (inertia = 1.2, radius 0.35) spins its wheels to more than twice the road speed on ice (forwardFriction = 0.15) and the car gains 2.2 m/s in 2 s, while on asphalt it pulls away with a slip ratio under 0.09 and reaches 8.6 m/s. The drive spins the wheel up to maxDriveSpeed at its tread and holds it there, the way a rev limit holds an engine: the same car with maxDriveSpeed = 25 and 1500 N·m on each rear wheel spins its rear treads to 25 m/s from rest on asphalt and in the air and no faster, and still spins them past twice the road speed pulling away on forwardFriction = 0.15. VehicleController sets it from its topSpeed. With maxDriveSpeed 0 motorTorque acts whatever the wheel's spin, so a wheel driven past its grip keeps spinning up until the drive eases. VehicleController's tractionControl eases it: it holds each driven wheel's drive to what its tyre pushes back with just short of the slip its grip peaks at, read from Physics.tyreCurve; a driver of your own does the same by cutting motorTorque while slipRatio stands past a target (0.1 to 0.5) the way the drive turns the wheel.
  • Lock-up. A brake torque past what the tyre holds stops the wheel (angularVelocity 0, slipRatio -1) while the chassis slides on, and a sliding tyre grips with slideGrip of its grip. The same car braked from 20 m/s stops in 26.9 m with every wheel locked (20000 N·m), and in 22.5 m with each brake held at 0.95 of what its tyre holds at the load it reads. A locked tyre holds only slideGrip of its grip, so a brake held at the peak keeps it locked: anti-lock braking is a driver that eases brakeTorque off while slipRatio stands past about 0.15 against the way the car rolls (below -0.15 rolling forward), letting the wheel roll again.
  • Drift. A tyre's grip along the road and across it is one grip: a tyre slid past its peak, spinning or locked, pushes against its slip in both directions with slideGrip of it, so the rear wheels of a car locked on the handbrake, or spun up under power, let go across the road and the car rotates into a drift (slipAngle on the rear tyres). Throttle and counter-steer hold it: from 15 m/s, the rear pair locked on 6000 N·m with the front steered 20 degrees for 0.7 s turns the car 32 degrees across its path, and 450 N·m on the rear with the front steered along the way the car moves holds it past 10 degrees for 1.6 s; a rear-driven car kicked into a slide at 10 m/s holds it past 10 degrees for 2.6 s with its throttle cut while the rear slip ratio stands above 0.5. Holding the throttle with the rear wheels spinning far past that leaves them next to no grip across the road, and the car spins. VehicleController's counterSteer gives a car that counter-steer from the controller: it steers the front wheels along the way the car moves as it slides, so a car driven from keys that steer full lock or none holds a drift on the throttle and the steering keys (the VehicleController README, "Holding a slide").

A wheel in the air keeps its spin, turned by its drive up to maxDriveSpeed and slowed by its brake. A chassis lying still with its wheels spinning in the air (on its roof, say) falls asleep like any other body, and its wheels spin on from where they were when it wakes. A wheel with no inertia (the default) rolls at the road speed.

Grip curve: peak, fall-off and load sensitivity

A tyre's grip is a curve over its slip (a tyre or tire curve, or grip curve). Along the road its force rises with the slip ratio at forwardFrictionStiffness times 10 per newton of load, and across it with the slip angle (its tangent) at sideFrictionStiffness times corneringStiffness per newton, each up to its peak: forwardFriction and sidewaysFriction times the load. The two directions share one grip, an ellipse their two peaks span, so a tyre braking or driving hard has less left for cornering. On a wheel that spins on its own, past the peak the grip falls in a straight line to slideGrip of it at slideSlip times the peak slip and stays there, the tyre pushing against its slip; a wheel with no inertia grips up to its peak across the road and holds it there. A loadSensitivity above 0 makes the tyre grip with less per newton the more it carries, every grip and stiffness scaled by (load / referenceLoad) ^ -loadSensitivity: a heavy vehicle grips with less per kilogram than a light one on the same tyres, and a wheel loaded by weight transfer (the outside wheels in a corner, the front ones under braking) gains less grip than the load it takes, so a car's balance moves with its load. The whole force is held to frictionSlip times the load as well.

So a tyre is stated by its peak (forwardFriction, sidewaysFriction), where it peaks (the stiffnesses), how it falls off (slideGrip, slideSlip) and how it takes load (loadSensitivity, referenceLoad): a peaky sim tyre, a forgiving drift tyre, a kart's, a truck's, a tyre on ice or on gravel. @builtin::modules.tyres holds presets of these fields (road, grippy, peaky, drift, loose, ice, heavy), as content, and any curve the fields state is one the engine takes:

local Tyres = require("@builtin::modules.tyres")
wheel.component.add("WheelCollider", Tyres.with("drift", { radius = 0.35, inertia = 1.2 }))

Physics.tyreCurve(wheelId, opts?) (the phys.tyreCurve tool) measures the curve a wheel states: its force against slip angle and, for a wheel that spins on its own, against slip ratio, at each load asked for, with each sweep's peak and slide and gripScale, the share of its stated grip it has per newton at that load. It is the force the wheel's solve settles on at that slip, so a tune can be checked by numbers before it is driven.

Measured on a 600 kg car on four wheels that spin on their own (inertia = 1.2, radius 0.35), at the engine's 30 Hz and 60 Hz ticks. A grippy curve (peak 1.2, falling to 0.9 of it by 3 peaks) corners at 11.0 to 11.1 m/s² on a skidpad, reaches 17.5 m/s after 2 s of 600 N·m on each wheel and stops from 20 m/s in 18 to 18.5 m with every wheel locked; the default curve (1, falling to 0.75 by 2) corners at 8.2 to 8.6 m/s², reaches 14.7 m/s and stops in 26.2 to 26.7 m; a peaky curve (1.2, falling to 0.5 by 1.2) corners at 7.5 to 8.5 m/s², reaches 12.0 m/s and stops in 32.5 to 33.3 m, and a handbrake turn from 15 m/s swings it 32 degrees across its path before counter-steer straightens it out; a slidey curve (0.8, falling to 0.4 by 1.5) corners at 5.1 to 5.6 m/s², reaches 6.4 m/s, is still sliding 6 s into the stop, and ends the same handbrake turn still 12 degrees across its path. With a loadSensitivity of 0.3 the car at 1200 kg (springs, dampers and maxSuspensionForce doubled) corners at 0.82 of the 600 kg car's peak, against the stated 2 ^ -0.3 = 0.81, and at 0 at the same one; with 0.5 and referenceLoad at its wheels' static load, weight transfer onto the outside wheels lowers its skidpad peak by 2.3 to 2.6%.

Solid wheels

A wheel's suspension is a ray, so on its own a wheel has no volume: a post, a wall or another car meets the chassis' collider and passes through the tyre. A solid wheel carries a volume as well, riding with the wheel centre as the suspension travels and steering with it: the wheel entity's own collider when it has one that is not a trigger (a SphereCollider, or a MeshCollider hull of a tyre model on the wheel entity), else a cylinder of the wheel's radius and width about its axle. Walls, posts and other bodies strike it on its tread and on its faces, the contact holds the chassis back as a contact on the chassis' own collider does, and contact events name the wheel entity (otherCollider). Its contacts low on its tread, in the cap under the wheel centre that groundAngle spans (below the centre by the radius times the cosine of the angle), are the suspension's: the ground, a ramp, a kerb or a plank met there is mounted by the suspension as a ray-only wheel mounts it, and a car on solid wheels settles and drives as the same car on ray-only wheels does. With the default 45 degrees a wheel of radius 0.35 m mounts a kerb up to 10 cm high and strikes anything taller. The cylinder adds no mass to the chassis and takes the collision groups of the chassis' colliders; a collider of the wheel's own keeps its own. A trigger on the wheel entity stays a trigger beside the volume, standing where the wheel entity stands on the chassis.

Wheels that come off

A wheel comes off its vehicle when its reaction passes its breakLoad, or when attached is set false (Physics.detachWheel(wheel)). It leaves as a dynamic body of its own, on the wheel entity, with its mass and with the wheel entity's own collider as its collider, whenever it is taken off and whether or not it is solid: that collider leaves the chassis with it, and the chassis' mass, centre of mass and inertia are worked out again over the colliders it keeps. A wheel with no collider of its own, or whose own collider is a trigger, leaves on a cylinder of its radius and width, and a trigger of its own leaves the chassis with it on its body and goes back to its mount with it. It rolls, bounces and lies down like any body, and Physics.getVelocity, Physics.applyImpulse and the contact listeners reach it. The wheel entity stays under the chassis in the hierarchy, standing where its own body is, and its visual follows that body. The vehicle drives on the wheels it has left, the others keeping their suspension, spin and tyre state, and a ShaftNetwork part naming the wheel turns on its own (its problem says the wheel came off) until it goes back on.

The mount is a fuse: a wheel torn off by its breakLoad passes its chassis no more than that over the tick it breaks in, of the blow's push and of the turn it gives the car alike. The wheel leaves moving as the blow left it, and the chassis keeps the rest of its momentum, so a car whose front wheel strikes a post carries on past it on its other wheels while the wheel stays at the post. Carrying on along its line, the car brings the wheel behind the torn one to the same post: a breakLoad that wheel's glancing blow stays under keeps it on, and a lower one sheds it too. A wheel taken off by command leaves moving as its chassis moved where it stood, spinning as it spun.

reaction is a force over one physics tick. A 600 kg car on four wheels reads about 1.5 to 2 kN per wheel at rest and about 1.9 kN rolling over an 8 cm kerb at 15 m/s; striking a post at 15 m/s with one solid wheel reads about 285 kN at a 30 Hz tick and 570 kN at 60 Hz (the same blow over half the time). A breakLoad of a few tens of kN keeps wheels on through kerbs, jumps and landings and loses them to a crash.

Set attached true again (Physics.attachWheel(wheel)) and the wheel goes back on its mount: its own body goes, and the vehicle drives on it from the next physics tick. Physics.vehicleState(chassis) lists the wheels on the vehicle under wheels and those that came off under detachedWheels, each with its detachReason and detachLoad. attached and detachReason are synced fields: on a shared world the peer simulating the vehicle breaks its wheels, every peer takes the wheel off, and the wheel's body moves on every other peer as the simulating peer moves it.

Seeing the suspension

capture { pass = "physics" } and the edit-mode collider overlay draw every wheel over the colliders: its suspension ray over its whole reach, suspensionDistance and the radius below the mount (green on ground, red in the air, as isGrounded reads), the travel from the mount to the tyre's centre coloured by how much of it is taken up (blue extended, yellow half way, red bottomed out), the tyre's radius as a white circle across its steered axle, and where the tyre meets the ground (yellow) with the ground's normal (cyan). Physics.debugLines({ layers = { "wheels" }, entities = { chassis } }) returns those lines with each wheel's grounded and compression (the same values as isGrounded and compression here), travel, suspensionLength, restLength, radius, mount and contactPoint / contactNormal. In edit mode the vehicle stands at rest, so its wheels draw where they are mounted and follow their authored fields as they change.

Visuals

The wheel entity's transform is the suspension mount, so it stays where it is authored. Put the tyre mesh on another entity under the chassis (a child of the wheel is the usual place) and name it in visual, as the entity or its id (a prefab or player clone of the car points it at its own copy of the tyre): every tick the wheel places that entity at the wheel centre, turns it by the steering angle and spins it about the axle, starting from the rotation it had when the wheel first posed it.

Methods: setMotor(torque), setBrake(torque), setSteer(angle).

local car = entity.spawn("car")
car.position = { 0, 1, 0 }
car.component.add("Physics", { kind = "dynamic", mass = 600 })
car.component.add("BoxCollider", { half = { 0.9, 0.3, 2.0 } })

for _, at in { { -0.85, -1.3 }, { 0.85, -1.3 }, { -0.85, 1.3 }, { 0.85, 1.3 } } do
    local wheel = entity.spawn("wheel", { parent = car.id })
    wheel.localPosition = { at[1], -0.3, at[2] }
    local tyre = entity.spawn("tyre", { parent = wheel.id })
    tyre.component.add("Model", { model = "cylinder" })
    tyre.localRotation = { 0, 0, 0.7071068, 0.7071068 } -- the cylinder's axis along X
    tyre.localScale = { 0.7, 0.25, 0.7 }
    wheel.component.add("WheelCollider", {
        suspensionDistance = 0.3,
        springRate = 20000,
        damperRate = 2000,
        visual = tyre,
    })
end