Rotation2D

View source

ExtendsAngle

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

Store the angular rate in radians, using positive and negative values for opposite directions. Use it with Orientation2D when an entity needs both angular motion and a current orientation. The component follows the radian representation and default value supplied by Angle.

Examples

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

const world = new World()
world.spawn([new Rotation2D(Math.PI / 2)])

const rotations = new Query(world, [Rotation2D])
rotations.each(([rotation]) => {
  // Set the entity's angular rate to one quarter turn per second.
  rotation.value = Math.PI / 2
})

Constructor


constructor(rad?: number)

View source

Creates an angle in radians.

Parameters

NameDescriptionDefault
rad?——

Methods


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

View source

Copies the angular motion value from one Rotation2D to another.

Parameters

NameDescriptionDefault
source

Component to copy.

—
target?

Component to update.

...

Returns

The updated target component.

staticclone(target: Rotation2D): Rotation2D

View source

Creates a new Rotation2D with the same angular motion value as the supplied component.

Parameters

NameDescriptionDefault
target

Component to copy.

—

Returns

A new component with the copied value.

staticserialize(value: Rotation2D): number

View source

Serializes a Rotation2D to its scalar radian representation.

Parameters

NameDescriptionDefault
value

Component to serialize.

—

Returns

The serialized radian value.

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

View source

Creates or updates a Rotation2D from a serialized radian value.

Parameters

NameDescriptionDefault
value

Serialized radian value.

—
out?

Component to update.

...

Returns

The updated component.