Skip to main content

Ricochet2DFSM

@zylem/game-lib


@zylem/game-lib / behavior / Ricochet2DFSM

Class: Ricochet2DFSM

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:102

FSM wrapper with extended state (lastResult). Systems or consumers call computeRicochet(...) when a collision occurs.

Constructors​

Constructor​

new Ricochet2DFSM(): Ricochet2DFSM

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:108

Returns​

Ricochet2DFSM

Properties​

machine​

readonly machine: SyncStateMachine<Ricochet2DState, Ricochet2DEvent, never>

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:103

Methods​

addListener()​

addListener(callback): () => void

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:113

Add a listener for ricochet events.

Parameters​

callback​

RicochetCallback

Returns​

Unsubscribe function

() => void


clearRicochet()​

clearRicochet(): void

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:179

Clear the ricochet state (call after consumer has applied the result).

Returns​

void


computeRicochet()​

computeRicochet(ctx, options?): Ricochet2DResult | null

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:145

Compute a ricochet result from collision context. Returns the result for the consumer to apply, or null if invalid input.

Parameters​

ctx​

Ricochet2DCollisionContext

options?​
maxAngleDeg?​

number

maxSpeed?​

number

minSpeed?​

number

reflectionMode?​

"simple" | "angled"

speedMultiplier?​

number

Returns​

Ricochet2DResult | null


getLastResult()​

getLastResult(): Ricochet2DResult | null

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:122

Returns the last computed ricochet result, or null if none.

Returns​

Ricochet2DResult | null


getLastUpdatedAtMs()​

getLastUpdatedAtMs(): number | null

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:126

Best-effort timestamp (ms) of the last computation.

Returns​

number | null


getState()​

getState(): Ricochet2DState

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:118

Returns​

Ricochet2DState


isOnCooldown()​

isOnCooldown(cooldownMs?): boolean

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:136

Check if ricochet is on cooldown (to prevent rapid duplicate applications).

Parameters​

cooldownMs?​

number

Cooldown duration in milliseconds (default: 50ms)

Returns​

boolean


resetCooldown()​

resetCooldown(): void

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:140

Reset cooldown state (e.g., on entity respawn).

Returns​

void


setCurrentTimeMs()​

setCurrentTimeMs(timeMs): void

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/ricochet-2d.d.ts:131

Set current game time (called by system each frame). Used for cooldown calculations.

Parameters​

timeMs​

number

Returns​

void