Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

phys

Set up and control physics on entities — spawn bodies, attach and change them, join them, constrain them, and filter their collisions — each in one ergonomic call.

Spawn an entity with a Model and a dynamic body or a static collider in one step. On an existing entity, attach or strip a body and collider, or change a body's kind (dynamic, kinematic, static) at runtime while preserving its mass, colliders, and joints — the move behind ragdoll activation and freeze/unfreeze. Join two entities with a validated physics joint, or remove an entity's joints; either end of a joint may be a soft body, anchored on a region of its particles. Hold a region of a soft body to a rigid body (a flag's edge on its pole, a body shell on a car's chassis) with attachSoftRegion, and release it with detachSoftRegion. Add transform constraints (position, rotation, scale, look-at, parent, aim) that run every frame and work even on entities without a physics body, and remove them by index. Lock rotation or translation on chosen axes, ignore collisions between a specific pair, or set an entity's collision groups and filter. Each op adds a viz flash so the change is visible from any camera.

Five verbs read rather than write. worldState reports what the simulation is holding (bodies by type, awake and asleep counts, colliders, joints, contact pairs and points, gravity, the timestep and the last step's cost), and whyStill answers why the solver is not moving one body, naming the nearest cause from a closed set. Both read the solver rather than the Physics component. tyreCurve measures a WheelCollider wheel's tyre grip curve, its force against slip ratio and slip angle at the loads asked for, with each curve's peak and slide, so a tyre is tuned by numbers. softBodyEnergy reads a soft body's energy ledger: what it holds, and since a mark what plastic flow and tearing absorbed and what it lost otherwise, by region; measureSoftBody measures a soft body's response to a stated press, impact or drop on a copy of it, force against displacement with the energy it absorbed. All five answer in edit mode as well as play mode.

advance fast-forwards the simulation: it runs a stated number of fixed steps, or a stated span of simulated seconds, as fast as the machine computes them, each the step real-time play runs (step hooks, held forces, contact events, fixedUpdate), so an outcome over many simulated seconds is measured in less wall time than the seconds it covers, and a paused simulation advances exactly the steps asked.

replay records a stretch of the simulation and plays it back at any speed, forwards or backwards, from any camera: an instant replay, a crash in slow motion, a kill cam. Playing draws the recording and leaves the live simulation where it was.

snapshot puts the whole simulation back to a moment: it takes a snapshot under a name (bodies, joints, soft bodies with their dents, contacts, vehicles), restores it so the next steps run exactly as they ran from it, bit for bit, as often as asked (test a bridge and reset it, retry a crash), and saves it to a VFS file or loads one back.