Physics
Adds rigid body dynamics to an entity. Body kind is `"dynamic"` (affected by forces), `"static"` (immovable), or `"kinematic"` (moved by script, affects other bodies).
Physics
Adds rigid body dynamics to an entity. Body kind is "dynamic" (affected by forces), "static" (immovable), or "kinematic" (moved by script, affects other bodies).
Public fields: kind, gravityScale, mass, linearDamping, angularDamping, ccd, interpolation, lockRotationX/Y/Z, lockTranslationX/Y/Z.
ccd (continuous collision detection) sweeps the body along its motion so it cannot pass through thin geometry between two steps. It is off by default: the sweep runs on every body that travels further than its own thickness in one step — most of a collapsing structure or a debris burst — and it dominates the physics budget when a scene has many such bodies. Turn it on for the individual bodies that would visibly tunnel: bullets, thrown props, a wrecking ball.
entity(id).component.add("Physics", { kind = "dynamic", ccd = true })
Methods: :applyForce(x, y, z), :applyImpulse(x, y, z), :applyTorque(x, y, z), :setVelocity(x, y, z), :addVelocity(dx, dy, dz).
entity(id).component.add("Physics", { kind = "dynamic" })
entity(id).component.get("Physics"):applyImpulse(5, 0, 0)
Scoped to this part · feeds back into the world's score.