Skip to content

world

FreeBodyEngine.core.physics.world #

PhysicsWorld - the rigid-body physics step.

Ties everything else in this package together: finds every RigidBody2D/ Joint2D in the scene, runs broad-phase then narrow-phase collision detection, solves every contact and joint together via sequential impulses, integrates positions, updates sleep state, and fires collision/ trigger events - once per fixed-timestep physics tick. core.scene.Scene calls step() directly; nothing else in the engine needs to.

No object here persists physics state across steps except the bodies themselves (RigidBody2D.touching, .is_sleeping, etc.) - this module just re-discovers the scene's bodies/joints fresh every step (the same convention PhysicsBody/Ray2D already use elsewhere in this codebase) rather than requiring a body to be explicitly registered with some separate persistent world object.

BAUMGARTE = 0.2 module-attribute #

GRAVITY = Vector(0, -9.8) module-attribute #

LINEAR_SLOP = 0.005 module-attribute #

MAX_CORRECTION_SPEED = 4.0 module-attribute #

SLEEP_ANGULAR_THRESHOLD = 3.0 module-attribute #

SLEEP_LINEAR_THRESHOLD = 0.05 module-attribute #

SLEEP_TIME_THRESHOLD = 0.5 module-attribute #

VELOCITY_ITERATIONS = 8 module-attribute #

step(scene, dt) #

Runs one fixed-timestep physics step for every RigidBody2D/Joint2D in scene - called by Scene._physics_process() alongside the older PhysicsBody loop (the two systems coexist; a scene can freely mix both kinds of body, they just don't interact with each other).