AM_Avatar

AM_Avatar

Extends the smoothed actor mixin to create an avatar under direct user control. Movement commands are routed through the pawn to the actor. The pawn speculatively executes these movement commands for a more responsive user experience. (Otherwise the actor wouldn't respond until the command had made the round trip through the reflector and back.)

The pawn still converges on the actor's "true position", so if the pawn's speculative execution turns out to be in error, it will automatically correct itself over the next few frames.

Instead of setting an avatar actor's translation and rotation directly, avatar pawns usually set the actor's velocity and spin instead. This allows the actor to update its own position during its tick, rather than the pawn sending every position change through the reflector.

Note - AM_Avatar must be paired with PM_Avatar in the pawn.

Extends

Members

# tickStep :Array.<number>

The frequency in milliseconds of the actor's tick method. Every tick the actor will apply its velocity and spin to adjust its position. Generally, for a first-person avatar you want to leave this at its default of 15ms so that it runs every frame.

Type:
  • Array.<number>
Default Value:
  • 15

# velocity :Array.<number>

The velocity of the actor in units/millisecond. Every tick the actor will move the velocity from its current position. The velocity is a 3-vector.

Warning: You usually shouldn't set an avatar's velocity directly. Instead let it be controlled automatically by events from the avatar's pawn.

Type:
  • Array.<number>
Default Value:
  • [0,0,0]

# spin :Array.<number>

The spin of the actor in radians/millisecond. Every tick the actor will rotate the spin from its current position. The spin is a quaternion.

Warning: You usually shouldn't set an avatar's spin directly. Instead let it be controlled automatically by events from the avatar's pawn.

Type:
  • Array.<number>
Default Value:
  • [0,0,0,1]

# translation :Array.<number>

The local translation of the actor relative to its parent. The value is a 3D vector.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0]
Fires:
  • translationChanged
  • localChanged
  • globalChanged
Example:
spatialActor.set({translation: [1,0,0]}); // Translate this actor one unit in the X direction from its parent.

# rotation :Array.<number>

The local rotation of the actor relative to its parent. The value is a quaternion.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0,1]
Fires:
  • rotationChanged
  • localChanged
  • globalChanged
Example:
spatialActor.set({rotation: q_axisAngle([1,0,0], toRad(90))}); // Rotate this actor 90 degrees around the X axis relative to its parent.

# scale :Array.<number>

The local scale of the actor relative to its parent. The value is a 3D vector.

Warning: Do not set the scale to 0!

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [1,1,1]
Fires:
  • scaleChanged
  • localChanged
  • globalChanged
Example:
spatialActor.set({scale: [2,2,2])}); // Double the size of this actor relative to its parent.

# local :Array.<number>

The local 4x4 transformation matrix. This is the actor's transform relative to its parent.

Warning - Do NOT set this matrix directly. Set the independent translation, rotation, and scale components and let the actor combine them to get the local matrix.

Type:
  • Array.<number>
Inherited From:

# global :Array.<number>

The global 4x4 transformation matrix. This is the actor's transform relative to world space, taking into account its local transform and the local transforms of all of its parents.

Warning - Do NOT set this matrix directly. Set the independent translation, rotation, and scale components and let the actor combine them to get the global matrix.

Type:
  • Array.<number>
Inherited From:

# parent :Actor

The parent of the actor in the hierarchical tree.

Type:
Inherited From:
Example:
const treeActor = TreeActor.create({parent: parentActor});

Methods

# tick()

The actor's tick runs every tickStep milliseconds. It will use the actor's velocity and spin to automatically update the translation and rotation. You can overload the tick method if the actor needs to perform other periodic updates.

Default Value:
  • 15

# moveTo(translation)

Tells the actor to move to a new xyz position. The actor moves immediately to the new translation, while its pawn smoothly interpolates over the next few frames. If you want the pawn to pop the new position, set the actor's translation property instead.

Note: All movement is relative to the actor's parent.

Parameters:
Name Type Description
translation Array.<number>

A 3-vector containing the new translation for the actor.

Inherited From:

# rotateTo(rotation)

Tells the actor to rotate to a new orientation. The actor moves immediately to the new rotation, while its pawn smoothly interpolates over the next few frames. If you want the pawn to pop the new position, set the actor's rotation property instead.

Note: All movement is relative to the actor's parent.

Parameters:
Name Type Description
rotation Array.<number>

A quaternion containing the new rotation for the actor.

Inherited From:

# scaleTo(scale)

Tells the actor to scale to a new size. The actor transitions immediately to the new scale, while its pawn smoothly interpolates over the next few frames. If you want the pawn to pop the new scale, set the actor's scale property instead.

Note: All movement is relative to the actor's parent.

Warning: Do not set the scale to 0!

Parameters:
Name Type Description
scale Array.<number>

A 3-vector containing the new scale for the actor.

Inherited From: