Physics
2D and 3D physics in Balaur through Rapier, stepped on a fixed 60 Hz tick with enhanced determinism: bodies, colliders, joints, characters and vehicles.
Pe această pagină
A plugin wrapping Rapier: rapier3d for body3d and
collider3d, rapier2d for body2d and collider2d. Both worlds run over
the same scene tree, built with Rapier's enhanced-determinism feature,
stepped on a fixed 60 Hz tick.
Declaring bodies
[[nodes]]
name = "Crate"
transform = { position = [0, 3, 0] }
body3d = { kind = "dynamic" } # dynamic | kinematic | static
collider3d = { shape = { kind = "box", size = [1.0, 1.0, 1.0] } }
self.node.set_component("body3d", { "kind": physics3d::BODY_DYNAMIC });
self.node.set_component("collider3d", { "shape": { "kind": physics3d::SHAPE_SPHERE, "radius": 0.5 } });
self.node.set_component("body2d", { "kind": physics2d::BODY_DYNAMIC });
self.node.set_component("collider2d", { "shape": { "kind": physics2d::SHAPE_RECTANGLE, "size": [1.0, 1.0] } });
- A collider's
shapetakeskind(sphereandboxin 3D,circleandrectanglein 2D, and a dozen more each) with the matching dimensions. - Plus
density, andrestitutionandfrictioninphysics_material. - A body's
massis its total, spread over its colliders' shapes; 0 sums what they weigh. collision_layerandcollision_maskname layers 1 to 32, as Godot's do.- Scene keys and script constants use the same names.
Component handles
self.node.body2d.apply_impulse(1.0, 0.0);
- A function that drives a component is a method on that component's handle.
node.body2dbinds to the module that drives the component.apply_impulseon abody3dhandle reachesphysics3d.- The node itself carries
get_component,set_component,patch_component,has_componentandremove_component. - A method no module declared for the component is a compile error naming it
(
node.sprite.apply_impulse). - Each component's methods are on its reference page, for example
body2d.
Driving the simulation
| Module | What is in it |
|---|---|
physics3d, physics2d |
Bodies, colliders, joints, velocities and queries, one module per world |
node.body2d, node.collider3d |
max_contact_impulse(), the strongest impact in the last step |
physics |
Both worlds: set_paused, is_paused, clear, set_sleeping_allowed, sleeping_allowed, the debug draw, the solver's tuning and counters |
The editor pauses physics until play. Its Physics workspace draws every body's collider and centre of mass over the scene, playing or not.

The full function lists are in the script modules reference.
Determinism
- Physics steps on a fixed 60 Hz tick.
- Order-sensitive collections iterate deterministically.
- Two runs with identical inputs match bit for bit. See Determinism.