Linear2DDamping

View source

Stores the scalar damping value for 2D linear motion.

Add Damping2DPlugin to an app’s world to provide this resource. Set value to control how strongly matching Velocity2D values are damped. The damping multiplier is 1 - value: 0 leaves velocity unchanged and 0.01 retains 99 percent of it. New instances default to 0, while the plugin-provided resource starts at 0.01.

The resource serializes to an object with one numeric value field and can be restored from that form. Serialized data must be a non-null object with a numeric value; no damping range is required.

Use the resource directly when an app needs to tune linear damping or save and restore its configuration.

Examples

import { Linear2DDamping } from '@wimaengine/damping'
import { World } from '@wimaengine/ecs'

const world = new World()
world.setResource(new Linear2DDamping(0.02))

const damping = world.getResource(Linear2DDamping)
damping.value = 0.01

Constructor


constructor(value?: number)

View source

Creates a 2D linear damping resource.

Parameters

NameDescriptionDefault
value?

Fraction removed from each 2D velocity update.

0

Properties


value: number

View source

Scalar damping value for matching 2D velocities.

The damping multiplier is 1 - value; for example, 0.01 retains 99 percent of the velocity.

Methods


staticdeserialize(value: Linear2DDampingSerial, out?: Linear2DDamping): Linear2DDamping

View source

Restores a 2D linear damping resource from its serialized value.

The method copies value.value without applying a range check. When out is supplied it is mutated and returned; otherwise a new resource is created.

Parameters

NameDescriptionDefault
value——
out?—...

staticvalidateSerial(value: unknown): value is Linear2DDampingSerial

View source

Checks whether a value has the serialized 2D damping shape.

This guard requires a non-null object with a value property whose type is number; it does not check whether the number is within a damping range.

Parameters

NameDescriptionDefault
value——