A handle to externally manipulate the player. The PlayerHandle stays the same even if the player changes their avatar. A user is treated as a different player every time they enter a room. Therefore, a new PlayerHandle will need to be acquired again for users who left and joined back in.

In events, ghosts and group viewing users cannot be retrieved from script. For details, refer to the documentation.

Hierarchy

  • PlayerHandle

Constructors

Properties

id: string

The string representation of the ID that uniquely identifies a player within the space. PlayerHandles sharing an identical id will all refer to the same player.

idfc: null | string

A string that creators can use to uniquely identify a user. This string is 32 characters long, using the characters 0123456789abcdef. This string is determined by the pair of the account that uploaded the item/world and the user's account. It does not change depending on the device or space used by the user. If the player does not exist, null is returned. The existence of a player can be checked with exists.

This string can be used to improve the content experience. We may restrict its use without notice if we deem it inappropriate.

userDisplayName: null | string

This is the player's Display Name. Users can change their own display name, and different users can use the same display name. If the player does not exist, null is returned. The existence of a player can be checked with exists.

userId: null | string

This is the player's User ID. Users can change their own user ID, but it is not possible for different users to have the same user ID at the same time. If the player does not exist, null is returned. The existence of a player can be checked with exists.

Methods

  • Beta

    Adds a velocity to the player. The actual movement speed of the player is determined from both the added velocity and player input. While the player is in contact with the ground, the added velocity will gradually decrease, similar to the effects of friction.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • velocity: Vector3

      Velocity to add (global coordinates)

    Returns void

  • If the player is in the room, returns true. This will still return true when a player is temporarily hidden for some reason, eg. connection issues.

    If the player does not exist, returns false.

    Returns boolean

  • Beta

    Obtains the position of a player's HumanoidBone. Values are in global coordinates. If the avatar has not finished loading yet, or the specified bone does not exist on the avatar, returns null.

    Parameters

    Returns null | Vector3

  • Beta

    Obtains the rotation of a player's HumanoidBone. Values are in global coordinates. If the avatar has not finished loading yet, or the specified bone does not exist on the avatar, returns null.

    Parameters

    Returns null | Quaternion

  • Obtains the current position of the player in global coordinates. If failed, returns null.

    Returns null | Vector3

  • Obtains the current rotation of the player in global coordinates. If failed, returns null.

    Returns null | Quaternion

  • Requests the player to purchase an purchasable item.

    The player who is requested to purchase the item will see a purchase dialog for the item. The result of the purchase request is received through the callback of ClusterScript.onRequestPurchaseStatus .

    If the player purchases the item, the callback of ClusterScript.onPurchaseUpdated will be called.

    If the player closes the dialog without purchasing the item, the purchase is canceled.

    If the player cannot display the purchase dialog, the request will be ignored. For example, this includes situations where the item purchase dialog is already being displayed.

    Differences in behavior based on room type:

    If executed during an event, the item cannot be purchased. When using ClusterScript.onRequestPurchaseStatus , the callback will receive PurchaseRequestStatus.NotAvailable.

    Frequency Limit:

    A single item can act on other ItemHandle and PlayerHandle up to 10 times per second. It is possible to momentarily exceed this limit, but please ensure the average number of calls does not surpass it. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) occurs, and the operation will fail.

    Example

    const productId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

    $.onStart(() => {
    // Save the player's status of owned purchasable items to the state.
    $.state.amounts = {};
    // Subscribe to purchase notifications.
    $.subscribePurchase(productId);
    });

    $.onUpdate(deltaTime => {
    // Check the purchase status of all players regularly, every 10 seconds.
    let timer = $.state.timer ?? 0;
    timer -= deltaTime;
    if (timer <= 0) {
    timer += 10;
    const allPlayers = $.getPlayersNear(new Vector3(), Infinity);
    $.getOwnProducts(productId, allPlayers, "onUpdate");
    }
    $.state.timer = timer;
    });

    $.onPurchaseUpdated((player, productId) => {
    // If the item is purchased, immediately check the player's purchase status.
    $.getOwnProducts(productId, player, "onPurchaseUpdated");
    });

    $.onGetOwnProducts((ownProducts, meta, errorReason) => {
    // Write the status of owned purchasable items to the state.
    let amounts = $.state.amounts;
    for (let ownProduct of ownProducts) {
    let playerId = ownProduct.player.id;
    let oldAmount = amounts[playerId] ?? 0;
    let newAmount = ownProduct.plusAmount - ownProduct.minusAmount;
    amounts[playerId] = newAmount;
    }
    $.state.amounts = amounts;
    });

    Parameters

    • productId: string

      The product ID for which a purchase is requested.

    • meta: string

      A string less than 100 bytes. It can be used to identify multiple requestPurchase calls. It is fine to specify an empty string or the same string multiple times.

    Returns void

  • Requests the player to input a text string.

    The text string from the player can be received in a callback set in ClusterScript.onTextInput. If the player is unable to respond to the input request, the request is automatically refused. An example of this is a situation where the player received a new input request, but was already in the middle of an earlier input request. The player can also intentionally refuse input requests. The outcome of the input request is represented in TextInputStatus.

    Example

    $.onInteract(player => {
    player.requestTextInput("ask_name", "Hi, what is your name?");
    });

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • meta: string

      A text string in 100 bytes or less. Useful for distinguishing between multiple requestTextInput calls. Empty or reused strings are allowed.

    • title: string

      A text string to display to the player who received the input request. Must be 200 bytes or less.

    Returns void

  • Resets any movement velocity, jumping speed, and gravity applied to the player.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Returns void

  • Respawns the player.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Returns void

  • Beta

    Send a message to PlayerScript. The sent target is expected to call the callback set in PlayerScript.onReceive. For data types that can be used as the message's payload (the arg argument), refer to Sendable.

    Example

    The following is an example of sending an message.

    playerHandle.send("damage", 20);
    

    In the following example, the item handle is sent to the player who Interacted to the item.

    $.onInteract(player => {
    player.send("item-handle", $.itemHandle);
    });

    How to handle the received message is described in PlayerScript.onReceive of the receiving PlayerScript. In the following example, store the received ItemId in a variable. For this ItemId, you can perform processing such as PlayerScript.sendTo of a message when necessary.

    let itemId = null;
    _.onReceive((messageType, arg, sender) => {
    switch (messageType) {
    case "item-handle":
    itemId = arg;
    break;
    }
    });

    Sendable sent for PlayerScript will be converted to PlayerScriptSendable. Specifically, ItemHandle is converted to ItemId and PlayerHandle is converted to PlayerId.

    Frequency Limit:

    One item can be sent up to 10 times/second. You can exceed this limit momentarily, but the average number of times should be below this limit. If the limit is exceeded, ClusterScriptError (rateLimitExceeded) occurs and send fails.

    Capacity Limit:

    The data size of the encoded arg must be less than 1000 bytes. If the data size exceeds the limit, a warning will be displayed. Data size can be calculated with computeSendableSize.

    If the data size is much larger than the limit, ClusterScriptError (requestSizeLimitExceeded) will occur and send will fail.

    Parameters

    • messageType: string

      Arbitrary string of 100 bytes or less indicating the message type

    • arg: Sendable

      Message Payload

    Returns void

  • Modifies the gravitational acceleration applied to the player. (Units are in m/s^2.) The default is -9.81.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • gravity: number

      Gravitational acceleration value

    Returns void

  • Beta

    Overwrites the pose of the player's avatar model with the specified HumanoidPose. The pose data override method can be specified with option; see SetHumanoidPoseOption for properties that can be specified by option.

    The argument option can be omitted. If it is omitted, the default setting is used.

    If the rootPosition, rootRotation, or muscle of the given HumanoidPose are not defined, they will not be overwritten. Additionally, option.timeoutSeconds and option.timeoutTransitionSeconds won't affect behavior for unspecified elements and will not be overwritten. Pose overwrites will persist until the next time setHumanoidPose is called or the pose data is cancelled at the timeout specified by option.

    To remove all previous overwrites made with setHumanoidPose, pass a null or an empty HumanoidPose as the argument. If a null or empty HumanoidPose is passed with HumanoidPoseOption, it will transition to the remove all previous overwrites after HumanoidPoseOption.transitionSeconds.

    Pose overwrites made through setHumanoidPose will take precedence over pose changes made from emotes or RidableItems.

    In VR, items being grabbed by the player will follow the specified pose, but elements such as the first-person camera, UI controls, etc. will be unaffected.

    Example

    // Register a HumanoidAnimation with the ID "MyAnimation"
    const animation = $.humanoidAnimation("MyAnimation");
    // Overwrite the pose
    playerHandle.setHumanoidPose(animation.getSample(0));
    // Remove the overwrite
    playerHandle.setHumanoidPose(null);
    const animation = $.humanoidAnimation("MyAnimation");
    const interval = 0.1;
    const animationLength = animation.getLength();

    // Make the person you Interact with the target of the animation.
    $.onInteract(player => {
    if ($.state.player) {
    // Deactivate when the target is already present.
    $.state.player.setHumanoidPose(null);
    }
    $.state.animationTime = 0;
    $.state.waitingTime = 0;
    $.state.player = player;
    });

    $.onUpdate(deltaTime => {
    let player = $.state.player;
    if (!player || !player.exists()) return;

    let animationTime = $.state.animationTime + deltaTime;
    if (animationTime > animationLength) {
    animationTime = animationTime % animationLength;
    }
    let waitingTime = $.state.waitingTime + deltaTime;
    if (waitingTime >= interval) {
    let pose = animation.getSample(animationTime);
    // Transition the pose data over the amount of time since the last transmission.
    player.setHumanoidPose(pose, {transitionSeconds: waitingTime});
    waitingTime = 0;
    }
    $.state.animationTime = animationTime;
    $.state.waitingTime = waitingTime;
    });

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    Returns void

  • Modifies the player's jumping speed multiplier. The default is 1.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • jumpSpeedRate: number

      Jumping speed multiplier

    Returns void

  • Modifies the player's movement speed multiplier. The default is 1.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • moveSpeedRate: number

      Movement speed multiplier

    Returns void

  • Modifies the position of the player.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • position: Vector3

      The avatar's root position, corresponding to the bottom center of the avatar's feet. (global coordinates)

    Returns void

  • Beta

    Sets post-process effects for the player.

    Each time this method is called, the previously set PostProcessEffects are overwritten with the new PostProcessEffects.

    Setting null clears all effects.

    Frequency Limit:

    A single item can act on other ItemHandle and PlayerHandle up to 10 times per second. It is possible to momentarily exceed this limit, but please ensure the average number of calls does not surpass it. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) occurs, and the operation will fail.

    Example

    // The screen becomes very bright when interacted with
    $.onInteract((player) => {
    const effects = new PostProcessEffects();
    effects.bloom.active = true;
    effects.bloom.threshold.setValue(0.5);
    effects.bloom.intensity.setValue(10.0);
    player.setPostProcessEffects(effects);
    });

    Parameters

    Returns void

  • Modifies the rotation of the player. Note the body orientation will stay vertical. (the camera and neck directions will be affected by the pitch.)

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Parameters

    • rotation: Quaternion

      The player's rotation (global coordinates)

    Returns void

Generated using TypeDoc