Cluster Creator Kit Script Reference
    Preparing search index...

    Interface PlayerScriptPlayer

    A handle to manipulate PlayerScript. It can be accessed from _ objects.

    PlayerScript is generated by setting ClusterScript.setPlayerScript.

    interface PlayerScript {
        cameraHandle: CameraHandle;
        hapticsHandle: HapticsHandle;
        isAndroid: boolean;
        isDesktop: boolean;
        isIos: boolean;
        isMacOs: boolean;
        isMobile: boolean;
        isVr: boolean;
        isWindows: boolean;
        oscHandle: OscHandle;
        playerId: PlayerId;
        sourceItemId: ItemId;
        addVelocity(velocity: Vector3): void;
        computeSendableSize(arg: PlayerScriptSendable): number;
        getAccessoryProductIds(): string[];
        getAvatarMovementFlags(): number;
        getAvatarProductId(): string | null;
        getHumanoidBonePosition(bone: HumanoidBone): Vector3 | null;
        getHumanoidBoneRotation(bone: HumanoidBone): Quaternion | null;
        getIdfc(playerId: PlayerId): string | null;
        getPlayerStorageData(): PlayerScriptSendable;
        getPosition(): Vector3 | null;
        getPositionOf(playerId: PlayerId): Vector3 | null;
        getRotation(): Quaternion | null;
        getRotationOf(playerId: PlayerId): Quaternion | null;
        getUserDisplayName(playerId: PlayerId): string | null;
        getUserId(playerId: PlayerId): string | null;
        hideButton(index: number): void;
        humanoidAnimation(humanoidAnimationId: string): HumanoidAnimation;
        iconAsset(iconId: string): IconAsset;
        log(v: any): void;
        onButton(index: number, callback: (isDown: boolean) => void): void;
        onFrame(callback: (deltaTime: number) => void): void;
        onReceive(
            callback: (
                messageType: string,
                arg: PlayerScriptSendable,
                sender: PlayerId | ItemId,
            ) => void,
            option?: { item: boolean; player: boolean },
        ): void;
        playerLocalObject(id: string): PlayerLocalObject | null;
        raycast(
            position: Vector3,
            direction: Vector3,
            maxDistance: number,
        ): PlayerScriptRaycastResult | null;
        raycastAll(
            position: Vector3,
            direction: Vector3,
            maxDistance: number,
        ): PlayerScriptRaycastResult[];
        resetPlayerEffects(): void;
        respawn(): void;
        sendTo(
            id: PlayerId | ItemId,
            messageType: string,
            arg: PlayerScriptSendable,
        ): void;
        setGravity(gravity: number): void;
        setHumanoidBoneRotationOnFrame(
            bone: HumanoidBone,
            rotation: Quaternion,
        ): void;
        setHumanoidPoseOnFrame(pose: HumanoidPose, weight: number): void;
        setJumpSpeedRate(jumpSpeedRate: number): void;
        setMoveSpeedRate(moveSpeedRate: number): void;
        setPlayerStorageData(data: PlayerScriptSendable): void;
        setPosition(position: Vector3): void;
        setPostProcessEffects(effects: PostProcessEffects | null): void;
        setRotation(rotation: Quaternion): void;
        setVoiceVolumeRateOf(playerId: PlayerId, rate: number): void;
        showButton(index: number, icon: IconAsset): void;
        worldItemReference(worldItemReferenceId: string): ItemId;
    }
    Index

    Properties

    cameraHandle: CameraHandle

    Gets the handle to control camera movement.

    hapticsHandle: HapticsHandle

    Gets the handle to control vibration of the controllers or devices of the player.

    isAndroid: boolean

    Gets whether the player is in an Android environment.

    Returns true if in a Quest environment.

    isDesktop: boolean

    Gets whether the player is in a desktop environment.

    Returns false if in a VR or mobile environment.

    isIos: boolean

    Gets whether the player is in an iOS environment.

    isMacOs: boolean

    Gets whether the player is in a macOS environment.

    isMobile: boolean

    Gets whether the player is in a mobile environment.

    Returns false if in a VR or desktop environment.

    isVr: boolean

    Gets whether the player is using VR devices.

    isWindows: boolean

    Gets whether the player is in a Windows environment.

    oscHandle: OscHandle

    The handle to receive or send Open Sound Control (OSC) messages.

    playerId: PlayerId

    Player's PlayerId.

    sourceItemId: ItemId

    ItemId of the source Item that has the Player Script component that called ClusterScript.setPlayerScript.

    Methods

    • 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.

      Parameters

      • velocity: Vector3

        velocity (global coordinates)

      Returns void

    • Gets an array of product IDs for the accessory items currently used by the player.

      If the accessory being used is not a product, it will not be included in the array.
      While the player is editing accessories, it returns the product ID of the accessory that was used before editing.
      Immediately after the player saves accessories, it may return the product ID of the accessory that was used just before.
      Immediately after the player enters the space, it may return an empty array.

      Returns string[]

      An array of product IDs for the accessories currently used by the player.

    • Gets the avatar's movement and motion status as a list of bitmasked flags. The defined bitflags are as follows:

      • 0x0001: On if the avatar is on the ground, off if in the air due to jumping or falling
      • 0x0002: On if the avatar is climbing, off otherwise
      • 0x0004: On if the avatar is riding on items, off otherwise

      Flags may be added in future updates, so use a value with the bitflag masked.

      Returns number

      Flags about avatar movement status

      // Example of a function to get bit flags and output logs
      function getStatus() {
      let flags = _.getAvatarMovementFlags();
      let isGrounded = (flags & 0x0001) !== 0;
      let isClimbing = (flags & 0x0002) !== 0;
      let isRiding = (flags & 0x0004) !== 0;
      _.log(`isGrounded: ${isGrounded}, isClimbing: ${isClimbing}, isRiding: ${isRiding}`);
      }
    • Gets the product ID of the avatar item currently used by the player.

      If the avatar being used is not a product, it returns null.
      While the player is launching the Avatar Maker, it returns the product ID of the avatar that was used before launching the Avatar Maker.
      Immediately after the player changes the avatar, it may return the product ID of the avatar that was used just before.
      Immediately after the player enters the space, it may return null.

      Returns string | null

      The product ID of the avatar currently used by the player.

    • 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 Vector3 | null

    • 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 Quaternion | null

    • Get the value of IDFC of the player. The IDFC is 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 combination of the account that uploaded the item that is the source of the PlayerScript and the user's account. The source item is the item that called $.setPlayerScript() and can be obtained with _.sourceItemId. It does not change depending on the device or space used by the user. It returns null for players who have left the room or for invalid PlayerId.

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

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be obtained

      Returns string | null

    • Gets data in the player's PlayerStorage.

      This API is not available from Craft Items.

      For details on PlayerStorage, see PlayerScript.setPlayerStorageData.

      Returns PlayerScriptSendable

      The data currently saved in PlayerStorage

      // Example code to get the saved level when a player starts the game
      let level;
      const storageData = _.getPlayerStorageData();
      if (storageData === null) {
      level = 1;
      } else {
      level = storageData.level;
      }
    • Obtains the current position of the player in global coordinates.

      Returns null if the value cannot be obtained.

      You can also get player's movement status with PlayerScript.getAvatarMovementFlags.

      Returns Vector3 | null

      The player's position

    • Obtains the current position of the specified player in global coordinates.

      Returns null if the value cannot be obtained.

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be obtained

      Returns Vector3 | null

      The player's position

    • Obtains the current rotation of the player in global coordinates.

      Returns null if the value cannot be obtained.

      You can also get player's movement status with PlayerScript.getAvatarMovementFlags.

      Returns Quaternion | null

      The player's rotation

    • Obtains the current rotation of the specified player in global coordinates.

      Returns null if the value cannot be obtained.

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be obtained

      Returns Quaternion | null

      The player's rotation

    • Get the player's display name. Users can change their display names, and different users can use the same display name. It returns null for players who have left the room or for invalid PlayerId.

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be obtained

      Returns string | null

    • Get the player's User ID. Users can change their own User ID, but no two different users can have the same User ID at the same time. null is returned for players who have left the room or for invalid PlayerId.

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be obtained

      Returns string | null

    • Beta

      Hides the button shown by PlayerScript.showButton. Does nothing if the specified button is already hidden.

      In desktop and mobile environments, when called with index = 0, the behavior of the "Use" button will revert to normal, and the button availability will be controlled by UseItemTrigger and ClusterScript.onUse callback.

      Parameters

      • index: number

        The button number, either 0, 1, 2, or 3. Other value will result an error.

      Returns void

    • Locates an animation entry with the ID humanoidAnimationId within the item's HumanoidAnimationList, and returns a HumanoidAnimation object referring to it.

      For details on HumanoidAnimationList, refer to the documentation.

      Parameters

      • humanoidAnimationId: string

      Returns HumanoidAnimation

    • Beta

      Gets the icon object corresponding to the specified iconId defined by Icon Asset List component. See details of the component at Icon Asset List. You can use the data with PlayerScript.showButton to show the buttons with specified icon.

      Parameters

      • iconId: string

        Id of the icon asset

      Returns IconAsset

    • Output the toString contents of v to the log.

      Parameters

      • v: any

      Returns void

    • Beta

      Registers the callback method for the button shown by PlayerScript.showButton. The callback will be called with isDown = true when pressed, and called again with isDown = false when the button is released. The method is available before showing the button, and the registration state is maintained even if the button is hidden.

      If called multiple times, only the last registration will be valid per button index.

      This callback is not necessarily called with isDown = false after being called with isDown = true. For example, if you press a button and then call hideButton to hide the button, the callback with isDown = false will not be called.

      Parameters

      • index: number

        The button number, either 0, 1, 2, or 3. Other value will result an error.

      • callback: (isDown: boolean) => void

        method that is called when the button is pressed or released.

      Returns void

    • Register a callback that will be called every frame. This callback is guaranteed to be called every frame.

      If called multiple times, only the last registration is valid.

      Parameters

      • callback: (deltaTime: number) => void

      Returns void

      // Output logs at 10 second intervals.
      let t = 0;
      _.onFrame(deltaTime => {
      t += deltaTime;
      if (t > 10) {
      _.log("10 sec elapsed.");
      t -= 10;
      }
      });
    • Registers a callback to be called when this item receives a message sent from PlayerHandle.send or sent from PlayerScript.sendTo to PlayerId.

      If called multiple times, only the last registration will be valid.

      You can specify the type of message to receive with option.

      If option is not set, it will receive both messages from PlayerHandle.send and messages sent to PlayerId by PlayerScript.sendTo. PlayerScript.sendTo | PlayerScript.sendTo}.

      Parameters

      • callback: (
            messageType: string,
            arg: PlayerScriptSendable,
            sender: PlayerId | ItemId,
        ) => void

        sender represents the item or player from which it is sent.

      • Optionaloption: { item: boolean; player: boolean }

        Option to register callbacks. You can specify the type of message to receive。

      Returns void

      // Output log of messages sent.
      _.onReceive((messageType, arg, sender) => {
      _.log(`Received message: ${messageType}, ${arg}`);
      });
      // Outputs a log of messages sent. Receive only messages from items.
      _.onReceive((messageType, arg, sender) => {
      _.log(`Received message: ${messageType}, ${arg}`);
      }, { player: false, item: true });
    • Gets the object specified by id in Player Local Object Reference List. See detail at Player Local Object Reference List. Returns null if id is not defined in the component or the object does not match the condition defined in the component page.

      Parameters

      • id: string

        id of the object

      Returns PlayerLocalObject | null

    • Casts a ray, and returns the first object it collided with.

      Parameters

      • position: Vector3

        Origin of the ray (global coordinates)

      • direction: Vector3

        Direction of the ray (global coordinates)

      • maxDistance: number

        Maximum distance for performing collision detection

      Returns PlayerScriptRaycastResult | null

      The collided object (null if no collision)

    • Casts a ray, and returns all the objects it collided with.

      When a large number of colliders are included in the range, it may not be possible to retrieve all ItemHandles that meet the condition. In this case, a warning message will be output to the console.

      Parameters

      • position: Vector3

        Origin of the ray (global coordinates)

      • direction: Vector3

        Direction of the ray (global coordinates)

      • maxDistance: number

        Maximum distance for performing collision detection

      Returns PlayerScriptRaycastResult[]

      An array of the collided objects (order is undefined)

    • Resets any movement velocity, jumping speed, and gravity applied to the player. The movement speed, jump speed, and gravity specified by PlayerHandle will also be reset.

      Returns void

    • Respawns the player.

      Returns void

    • Send a message to the item or player.
      An item can receive the sent message in a callback set in ClusterScript.onReceive with { player: true } specified.
      A player can receive the sent message in a callback set in PlayerScript.onReceive.
      See PlayerScriptSendable for data that can be used in the message payload (the arg argument).

      Ignored for deleted items and for invalid ItemId.
      Ignored for players who have left the room and for invalid PlayerId.

      If sent for an ItemId, PlayerScriptSendable will be converted to Sendable.

      If a non-PlayerScriptSendable value, such as undefined, is passed to arg argument as the message's payload, it will be ignored. This behaviour may change in future releases.

      There is a limit on how often sendTo can be called.

      • When called from a craft item, it must not exceed 10 calls per second per item
      • When called from a world item, the total number of calls to ItemHandle.send, PlayerHandle.send, and PlayerScript.sendTo from all world items in the space must not exceed 3000 calls per second

      It is possible to momentarily exceed this limit, but please ensure the average number of calls stays below this limit. If the limit is exceeded, ClusterScriptError (rateLimitExceeded) occurs and the operation fails.

      When APIs subject to Flow Control, including this API, are called excessively frequently beyond the limit within a space, the results may be applied with significant delays. For more details, please refer to Flow Control.

      If the item running this script is a world item, the sendTo operation will only succeed if Flow Control Delay is 30 seconds or less. If the limit is exceeded, ClusterScriptError (rateLimitExceeded) occurs and the operation fails.

      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 PlayerScript.computeSendableSize.

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

      Parameters

      Returns void

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

      The setting is shared with PlayerHandle.setGravity. The value of the one called later will overwrite it.

      Parameters

      • gravity: number

        Gravitational acceleration value

      Returns void

    • Sets the specified bone's rotation. Values are in global coordinates. The rotation specified by this method is applied only to that frame and does not affect the next frame or later.

      This method does nothing when the specified bone does not exist in the avatar.

      The bone rotations specified by this function take precedence over the pose specified by PlayerHandle.setHumanoidPose. In VR, items held by the player will follow the specified pose, but the first-person camera and UI operations are not affected.

      Parameters

      Returns void

    • Overwrites the pose of the player's avatar model with the specified HumanoidPose. The pose specified by this method is applied only to that frame and does not affect the next frame or later.

      If the rootPosition, rootRotation, or muscle of the given HumanoidPose are not defined, they will not be overwritten.

      weight represents the application rate of the specified pose as a number between 0 and 1. Calling the method with weight = 1 applies the pose completely. weight is optional, and treated as 1 is specified if omitted.

      The pose specified by this function takes precedence over PlayerHandle.setHumanoidPose. In VR, items held by the player will follow the specified pose, but the first-person camera and UI operations are not affected.

      Parameters

      • pose: HumanoidPose

        The pose to apply

      • weight: number

        The weight to apply the pose

      Returns void

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

      The setting is shared with PlayerHandle.setJumpSpeedRate. The value of the one called later will overwrite it.

      Parameters

      • jumpSpeedRate: number

        Jumping speed multiplier

      Returns void

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

      The setting is shared with PlayerHandle.setMoveSpeedRate. The value of the one called later will overwrite it.

      Parameters

      • moveSpeedRate: number

        Movement speed multiplier

      Returns void

    • Overwrites data in the player's PlayerStorage.

      See PlayerScriptSendable for data that can be saved (the data argument).

      This API is not available from Craft Items.

      PlayerStorage is an area for saving data that exists per player in each world or event. If setPlayerStorageData has never been called, null is stored in the PlayerStorage.

      In worlds, the data in PlayerStorage is saved even if the player leaves the world. When the player returns to the world, they can get the saved data. PlayerStorage can also store PlayerId and ItemId, but these do not necessarily represent players or items that are valid in other spaces.

      In events, each time a player enters, PlayerStorage is initialized, and null is set. Even if the data in PlayerStorage is overwritten during an event, the data in PlayerStorage of the original Event Venue remains unchanged.

      The data in PlayerStorage can be deleted from the World Manager. See Resetting world save data for details.

      The data size of the encoded data must be less than or equal to 10,000 bytes. The data size can be calculated using PlayerScript.computeSendableSize.

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

      Parameters

      Returns void

      // Example code that levels up when receiving a levelUp message and saves the result.
      let level = 1;
      _.onReceive((messageType, arg, sender) => {
      if (messageType === "levelUp") {
      level += 1;
      _.setPlayerStorageData({ level });
      }
      });
    • Sets the position of the player in global coordinate.

      Parameters

      • position: Vector3

        The player's position

      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.

      The settings are shared with PlayerHandle.setPostProcessEffects. The value of the one called later will overwrite it.

      Parameters

      Returns void

      // A button that becomes very bright when pressed.
      _.onButton(0, (isDown) => {
      if (!isDown) return;
      const effects = new PostProcessEffects();
      effects.bloom.active = true;
      effects.bloom.threshold.setValue(0.5);
      effects.bloom.intensity.setValue(10.0);
      _.setPostProcessEffects(effects);
      });
    • Sets the rotation of the player in global coordinate.

      Note the body orientation will stay vertical.

      Parameters

      Returns void

    • Set the voice volume of the specified player that the player executing the Player Script hears. Changes made to one's own player will be ignored.

      The value specified in this method will be reset when the validity period of the Player Script expires.

      Parameters

      • playerId: PlayerId

        PlayerId of the player whose value is to be set

      • rate: number

        The rate of the volume to be set. The specified value is clamped between 0 and 1.

      Returns void

    • Beta

      Displays a button UI corresponding to the specified integer value, or starts monitoring key/mouse click inputs that are treated as equivalent to a button. If called on a button that is already displayed, the icon will be updated. Up to four button inputs can be presented in this way.

      To display buttons with this function, the Use Cluster HUD v2 option must be enabled on the world's WorldRuntimeSetting component. Use PlayerScript.onButton to register the callback for the buttons.

      In desktop and mobile environments, the button corresponding to index = 0 is the same as the "Use" button of the item with UseItemTrigger component. Other buttons are only displayed by calling this function. If this function is called with index = 0, the display content of the button set by this function and the callback registered with PlayerScript.onButton will take priority over the "Use" button of the item until PlayerScript.hideButton is called with index = 0. Pressing a button will not fire UseItemTrigger and ClusterScript.onUse callback.

      Buttons displayed by this function will be hidden when PlayerScript.hideButton is called or when the validity period of the Player Script expires.

      In a mobile environment, buttons are placed in specific positions according to their numbers. In a desktop environment, the following key assignments are applied to buttons 0, 1, 2, and 3.

      • 0: Left click
      • 1: Right click
      • 2: E key
      • 3: R key

      In a VR environment, when one or more buttons are enabled, pulling the trigger on the right-hand controller will display a pie menu. Tilting the stick then inputs the corresponding button. On the pie menu, the buttons correspond to 0, 1, 2, and 3, arranged counterclockwise starting from the right.

      In a desktop environment, cursor operation on the screen is locked while one or more buttons are displayed, and clicks and key inputs during cursor lock are treated as button inputs. If buttons are displayed and hidden very frequently, this automatic cursor lock will be disabled for a certain period of time.

      Parameters

      • index: number

        The button number, either 0, 1, 2, or 3. Other value will result an error.

      • icon: IconAsset

        The icon to show on the button. When the icon is invalid, then treated as the icon is not specified.

      Returns void

    • Returns an ItemId object that references the Item specified by worldItemReferenceId in the item's WorldItemReferenceList.

      For details on WorldItmeReferenceList, see documentation.

      Parameters

      • worldItemReferenceId: string

      Returns ItemId

      // Item that sends message "button" to the specified item when button 0 is pressed
      const target = _.worldItemReference("target");

      _.onButton(0, isDown => {
      if (isDown) _.sendTo(target, "button", null);
      });