physicspropertiesAddHook

View sourcephysicspropertiesAddHook(entity: EntityHandle, world: World): void

Recomputes inverse inertia when PhysicsProperties is added or inserted on an entity.

The component lifecycle invokes this function for add and insert callbacks, providing the affected entity and its owning world. The hook reads the entity’s Collider2D; when it exists, the hook converts invmass to mass, calculates the collider’s inertia, and writes the resulting inverse to invinertia.

If the entity has no Collider2D, the hook logs a warning and returns without changing invinertia. A zero inverse mass produces a zero mass, and a zero or otherwise falsy calculated inertia produces zero inverse inertia.

Examples

// The component lifecycle invokes this hook automatically.
const body = world.spawn([
  Collider2D.rectangle(1, 1),
  new PhysicsProperties()
])
// The component's inverse inertia is derived from its collider and mass.
console.log(world.get(body, PhysicsProperties).invinertia)

Parameters

NameDescriptionDefault
entity

Entity receiving the PhysicsProperties component.

—
world

World containing the entity and its components.

—