Skip to main content

Ricochet2DHandle

@zylem/game-lib


@zylem/game-lib / behavior / Ricochet2DHandle

Interface: Ricochet2DHandle

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:215

Handle methods provided by Ricochet2DBehavior

Methods​

applyRicochet()​

applyRicochet(ctx): 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:231

Compute ricochet and apply velocity directly via transformStore. Emits to onRicochet listeners if successful.

Parameters​

ctx​

Ricochet2DCollisionContext

Collision context with entity and contact normal

Returns​

boolean

true if ricochet was computed and applied, false otherwise


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:235

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

Returns​

Ricochet2DResult | null


getRicochet()​

getRicochet(ctx): 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:223

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

Parameters​

ctx​

Ricochet2DCollisionContext

Collision context with selfVelocity and contact normal

Returns​

Ricochet2DResult | null

Ricochet result with velocity, speed, and normal, or null


onRicochet()​

onRicochet(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:243

Register a listener for ricochet events. Called whenever a ricochet is computed (from getRicochet or applyRicochet).

Parameters​

callback​

RicochetCallback

Function to call with ricochet result

Returns​

Unsubscribe function

() => void