Skip to content

Kiln API / kiln/physics / PhysicsState

Class: PhysicsState ​

The Rapier world plus Kiln's entity mapping. Use res.mut(Physics) for impulses and raycasts.

Constructors ​

Constructor ​

ts
new PhysicsState(
   rapier, 
   world, 
   is2D
): PhysicsState;

Parameters ​

ParameterType
rapierany
worldany
is2Dboolean

Returns ​

PhysicsState

Properties ​

bodies ​

ts
readonly bodies: Map<Entity, Created>;

colliderOwner ​

ts
readonly colliderOwner: Map<number, Entity>;

eventQueue ​

ts
readonly eventQueue: any;

rapier ​

ts
readonly rapier: any;

world ​

ts
readonly world: any;

is2D ​

ts
readonly is2D: boolean;

Methods ​

bodyOf() ​

ts
bodyOf(e): any;

The Rapier body for an entity, once created (the step after RigidBody was added).

Parameters ​

ParameterType
eEntity

Returns ​

any


applyImpulse() ​

ts
applyImpulse(e, impulse): void;

Adds an instantaneous change in momentum (mass × velocity).

Parameters ​

ParameterType
eEntity
impulsePartial<Vec3>

Returns ​

void


setVelocity() ​

ts
setVelocity(e, v): void;

Sets linear velocity directly (same as writing LinearVelocity).

Parameters ​

ParameterType
eEntity
vPartial<Vec3>

Returns ​

void


raycast() ​

ts
raycast(
   origin, 
   dir, 
   maxDistance?, 
   exclude?
): RaycastHit | null;

Casts a ray and returns the first hit, or null. exclude skips one entity's colliders.

Parameters ​

ParameterTypeDefault value
originVec3undefined
dirVec3undefined
maxDistancenumber1000
exclude?Entityundefined

Returns ​

RaycastHit | null


remove() ​

ts
remove(e): void;

Parameters ​

ParameterType
eEntity

Returns ​

void