AvatarEventHandler

AvatarEventHandler

AvatarEventHandler Behavior Module

The Microverse system automatically attaches a behavior module named AvatarEventHandler to the Avatar. Its default implementation is stored in behaviors/croquet/avatarEvents.js, but you can create a behavior with a similar structure to override the default functionality of some methods defined at AvatarPawn.

When the card spec for the avatar has the avatarEventHandler property, the behavior module with the name is used (instead of a module named AvatarEventHandler. You can provide a custom action for a known method by defining a method at the pawn side behavior called AvatarPawn. (cf. behaviors/croquet/halfBodyAvatar.js in the source code).

Currently the following methods of the base AvatarPawn can be overridden. (In the source code the methods with this.call(...handlerModuleName...) lines checks if the named method exists in the behavior and calls if it does.)

Methods

# startMotion(dx, dy)

Called when the shell sends the motion-start DOM message from the Microverse shell, typically when the joystick is pressed down.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# updateMotion(dx, dy)

Called repeatedly when the shell sends the motion-update DOM message from the Microverse shell, typically when the joystick is moved from the off-center.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# endMotion(dx, dy)

Called when the shell sends the motion-end DOM message from the Microverse shell, typically when the joystick is released.

Parameters:
Name Type Description
dx number

the offset of joystick knob

dy number

the offset of joystick knob

# walkLook()

This method specifies the global camera position. The implementation can use various properties such as the global transformation of the avatar, lookPitch and other properties that the behavior defines.

Returns:

Matrix4

# walk(time, delta, vq)

This method receives the time and "delta", which is the elapsed time since last display animation frame time, and the proposed "pose" of the avtar based on the user interaction. The default implementation moves the proposed position based on the BVH collision detection and testing the edge of the walkable terrain and returns another pose. You can override the movement by supplying the walk method at your AvatarPawn behavior. (Its details is somewhat implementation dependent so please consult the actual source code.)

Parameters:
Name Type Description
time number

the animation frame time

delta number

the difference from the last animation frame time

vq Object

an object with the v property for proposed next position and q property for proposed next rotation

# pointerDown(evt)

Implementing them at the AvatarPawn overrides their actions. Note that the first responder and last responder mechanism is involved so some methods expects certain patterns. In general, you can simply copy the default implementation in src/avatar.js into your own behavior file as ther starting point for your own custom implementation.

Parameters:
Name Type Description
evt Event

the p3e event from Pointer.

# mapOpacity()

This method controls the opacity used to render avatars. Typically a remote avatar close to yours become translucent. the custom implementation of mapOpacity defined at the AvatarPawn maps the value in the [0, 1] range.

Returns:

a number to represent modified opacity between [0, 1]