Class
PhysicsProperties
View sourceStores the collision and mass properties for a physics body component.
Attach PhysicsProperties alongside a Collider2D to describe how
a body participates in collision detection and response. Inverse mass and
inverse inertia control linear and angular response.
A zero inverse mass makes the body immovable by collision impulses.
A zero inverse inertia prevents angular response.
group and mask are BigInt bit fields.
Two bodies pass the collision filter only when both intersections are non-zero: a.group & b.mask and b.group & a.mask.
The default values enable all lower 32 filter bits.
sleep causes a pair to be skipped when both bodies are sleeping. For an
accepted contact, the lower restitution and lower kinetic-friction value
from the pair is used.
A new instance has these defaults:
invinertia:0invmass:0mask:0xffffffffngroup:0xffffffffnsleep:falserestitution:0.7kineticFriction:0.6.
The component stores the supplied values as-is; it does not clamp material values or validate physical ranges.
Examples
import { World } from '@wimaengine/ecs'
import { Collider2D, PhysicsProperties } from '@wimaengine/narrowphase'
const world = new World()
const properties = new PhysicsProperties()
properties.invmass = 1 / 2
properties.group = 0b01n
properties.mask = 0b01n
properties.restitution = 0.4
const body = world.spawn([
Collider2D.rectangle(1, 1),
properties
])Constructor
Properties
invinertia: number
View sourceInverse moment of inertia used for angular collision response.
Default: 0
invmass: number
View sourceInverse mass used for linear collision response; 0 makes a body
immovable by collision impulses.
Default: 0
mask: bigint
View sourceCollision-category bits tested against another body’s group.
Default: 0xffffffffn
group: bigint
View sourceCollision-category bits tested against another body’s mask.
Default: 0xffffffffn
sleep: boolean
View sourceWhether this body is sleeping; two sleeping bodies are skipped as a pair.
Default: false
restitution: number
View sourceBounciness used by collision response; contacts use the lower pair value.
Default: 0.7
kineticFriction: number
View sourceKinetic friction used by collision response; contacts use the lower pair value.
Default: 0.6
Methods
staticcopy(source: PhysicsProperties, target?: PhysicsProperties): PhysicsProperties
View sourceCopies all seven fields from source into target.
When target is omitted, the method creates a new PhysicsProperties.
Values are assigned as-is, including BigInt filter fields.
staticclone(target: PhysicsProperties): PhysicsProperties
View sourceCreates a new component with the same seven field values as target.
staticdefault(): PhysicsProperties
View sourcestaticserialize(value: PhysicsProperties): PhysicsPropertiesSerial
View sourceConverts a component to its plain serialized field object.
BigInt mask and group values remain BigInt values; this method does not
convert them to numbers or strings.
staticdeserialize(value: PhysicsPropertiesSerial, out?: PhysicsProperties): PhysicsProperties
View sourceWrites serialized fields into a component.
The method does not validate value before reading it. Call
PhysicsProperties.validateSerial first when input
comes from an external source. If out is omitted, a new component is
created; otherwise the supplied component is updated and returned.
staticvalidateSerial(value: unknown): value is PhysicsPropertiesSerial
View sourceChecks whether a non-null object has all serialized fields with the required primitive types.
invinertia, invmass, restitution, and kineticFriction must be
numbers. mask and group must be BigInts, and sleep must be a
boolean. The check does not enforce finite numbers, bit width, sign, or
any other physical constraints. It checks field presence with the in
operator, so inherited fields also satisfy the presence check.
