Torque2D

View source

ExtendsAngle

Represents an entity’s accumulated angular input in 2D as an ECS component.

Its scalar value follows Angle and is expressed in radians. A new component starts at 0 radians. Use it with Rotation2D.

Examples

import { Query, World } from '@wimaengine/ecs'
import { Torque2D } from '@wimaengine/movable'

const world = new World()
world.spawn([new Torque2D()])

new Query(world, [Torque2D]).each(([torque]) => {
  // Accumulate a one-degree angular input.
  torque.value += Math.PI / 180
})

Constructor


constructor(rad?: number)

View source

Creates an angle in radians.

Parameters

NameDescriptionDefault
rad?——

Methods


staticcopy(source: Torque2D, target?: Torque2D): Torque2D

View source

Copies the scalar value from one Torque2D into another.

Parameters

NameDescriptionDefault
source

Component to copy.

—
target?

Component to update.

...

Returns

The updated target component.

staticclone(target: Torque2D): Torque2D

View source

Creates a new Torque2D with the same scalar value as the source.

Parameters

NameDescriptionDefault
target

Component to copy.

—

Returns

A new component with the copied value.

staticserialize(value: Torque2D): number

View source

Serializes a Torque2D to its scalar radian value.

Parameters

NameDescriptionDefault
value

Component to serialize.

—

Returns

The serialized radian value.

staticdeserialize(value: number, out?: Torque2D): Torque2D

View source

Creates or updates a Torque2D from a serialized scalar radian value.

Parameters

NameDescriptionDefault
value

Serialized radian value.

—
out?

Component to update.

...

Returns

The updated component.