Position3DAnimationEffector

View source

Applies interpolated 3D position values to an entity’s Position3D component.

This class implements the AnimationEffector contract for 3D position animation. Pass it to an AnimationTrack; each keyframe contains x, y, and z values in that order.

Examples

import { World } from '@wimaengine/ecs'
import { AnimationTrack, Position3DAnimationEffector } from '@wimaengine/animation'
import { Position3D } from '@wimaengine/transform'

const world = new World()
const entity = world.spawn([new Position3D()])
const track = new AnimationTrack(Position3DAnimationEffector)
track.times = [0, 1]
track.keyframes = [0, 0, 0, 10, 20, 30]

Position3DAnimationEffector.apply(world, entity, track.getCurrent(0.5))
// The entity's position is now (5, 10, 15).

Constructor


constructor()

Properties


Methods


staticapply(world: World, entity: EntityHandle, results: number[]): void

View source

Writes the current x, y, and z values to the target position component.

Position3DAnimationEffector.apply reads this.componentType from world for entity, then calls set(results[0], results[1], results[2]) on the returned component. It does not add a missing component or check the lookup result; a stale handle, an unknown entity, or an entity without the component therefore causes the subsequent set() call to fail.

Parameters

NameDescriptionDefault
world

World containing the target entity.

—
entity

Handle of the entity to update.

—
results

Interpolated values; indexes 0, 1, and 2 are x, y, and z.

—

staticelementSize(): number

View source

Returns the number of values consumed from each keyframe.

AnimationTrack therefore stores and interpolates three consecutive values per timestamp for this effector.

Returns

Always 3.