Skip to content
Character

[Character System](../groups/Character System.Character System.md) / Character

Character Class ​

Character


What is a character?

Character refers to the game entity representing the Player. It is the main object in the game that can move in the virtual world and interact with the environment and other character. Character can be regarded as a character player in the game. It can be a character control by the Player or a character control by the game system.

What functions does the character have?

Mobile and interactive. Character has the ability to move and interact with the environment in the game world. It can walk, run, jump or fly. According to the rules of the game and the design of character, Character can perform various actions.

Function and behavior. Characters can have various functions and behaviors. For example, a character can be a warrior with attack and defense skills; Another character could be a merchant, responsible for trading and providing goods. The functions and behaviors of Character are defined and implemented by game developers based on game requirements.

in general:

  1. Control character movement: You can use it to specify parameters such as character movement speed, direction, and acceleration. It allows you to programmatically control the movement of a character, such as making a character move forward, rotate, or jump. It also support multiple movement modes: for example, it can achieve linear movement, rotation, jumping, swimming, crouching and flying. According to your game needs, you can choose the appropriate mobile mode and use the corresponding API to achieve.

  2. Work with physical simulation and collision: It can use the physics engine to simulate character's gravity, collision, inertia and other effects. Through physical simulation, character can interact with other objects in the game world and be subject to reasonable physical influences. Perform collision detection: It can detect collisions between characters and walls, floors, or other characters and take corresponding actions. This helps achieve more realistic and reliable character movement and interaction.

  3. Handling character appearance: You can give characters various appearances. Choose the right clothes, equipment, and features for your character. Whether it's the tight fitting clothes of superheroes, the armor of medieval knights or the high-tech equipment of future soldiers, you can feel the unique style and personality of character.

  4. Achieve vivid animation: it can also give character vivid animation effects. It can enable character to jump, run, fight and even show various special skills and actions in the game.

Among them, the more important ones are:

  • addMovement The function control the movement of the character in a given direction.

  • loadAnimation The function loads the left animation resources onto the character, allowing them to freely use various actions.

  • description Change the appearance of the character's attributes. The left column provides a large number of clothing, accessories, and other resources for the character. Pass in the resource ID string to freely change the appearance.

Usage example: generate a character

ts
@Component
 export default class NewExample extends Script {
     protected onStart(): void {
         GameObject.asyncSpawn<Model>("183107",{transform: new Transform(new Vector(100,0,0),new Rotation(0,0,0),new Vector(1,1,1))}).then(()=>{
             Console.log ("success!");
         });
     }
}
@Component
 export default class NewExample extends Script {
     protected onStart(): void {
         GameObject.asyncSpawn<Model>("183107",{transform: new Transform(new Vector(100,0,0),new Rotation(0,0,0),new Vector(1,1,1))}).then(()=>{
             Console.log ("success!");
         });
     }
}

Hierarchy ​

  • Pawn

    ↳ Character

Table of contents ​

Properties ​

onDescriptionChange: MulticastDelegate<OnDescriptionChange> other
Commissioned changes in appearance loading details
onDescriptionComplete: MulticastDelegate<OnDescriptionComplete> other
When the character appearance is loaded, call delegate
onEmergeFromWater: MulticastDelegate<() => void> other
When the character swims up to the water surface in the swimming area, call delegate
onStateChanged: MulticastDelegate<(prevState: CharacterStateType, currentState: CharacterStateType) => void>
Character status change callback

Accessors ​

brakingDecelerationFlying(): number other
Get character's flight brake rate
brakingDecelerationSwimming(): number other
Get the character's swimming brake speed|
brakingDecelerationWalking(): number other
Set the character walking brake rate|
canStandOn(): boolean other
Get whether the character can be standing by other Player|
capsuleCorrectionEnabled(): boolean other
Get whether the character is currently using capsule correction|
characterType(): CharacterType
What type of character is obtained|
collisionExtent(): Vector other
Obtain the shape and size of the collision body of the package character|
collisionShape(): [CustomShapeType: CustomShapeType](../enums/mw.CustomShapeType.md) other
Obtain the collision shape of characters (capsule shape, ball shape, box shape)|
collisionWithOtherCharacterEnabled(): boolean other
Gets whether the character can currently collision with other character.
complexMovementEnabled(): boolean
Whether to enable the complex mobile policy
crouchedHeight(): number other
Get the height of the collision box in the character crouch state.
currentAnimation(): Animation
The currently playing animation object
currentStance(): Stance
Get the current playing basic pose
currentSubStance(): SubStance
Get the secondary stance currently playing, and the secondary stance type is SubStance
description(): CharacterDescription other
Character appearance configuration|
displayName(): string
Get character Name|
driftControl(): number other
Get the flexibility of character in the air|
forceUpdateMovement(value: boolean): void other
Force update Move
gravityScale(): number other
Obtain the magnification of gravity|
groundFriction(): number other
Obtain ground friction force
groundFrictionEnabled(): boolean other
Obtain separate brake friction status|
horizontalBrakingDecelerationFalling(): number other
Obtain the character's descent braking rate|
isCrouching(): boolean other
Get whether the character is squatting
isDescriptionReady(): boolean other
Get whether the current character appearance is ready|
isJumping(): boolean other
Get whether the character is jumping or not
isMoving(): boolean other
Get whether the character is moving
jumpMaxCount(): number other
Get the maximum number of hops a character can make|
maxAcceleration(): number other
Obtain the maximum acceleration of the character|
maxFallingSpeed(): number other
Set the maximum descent speed of the character|
maxFlySpeed(): number other
Obtain the maximum flight speed of the character|
maxJumpHeight(): number other
Get the maximum jump height of character|
maxStepHeight(): number other
Obtain the maximum height that the character can cross|
maxSwimSpeed(): number other
Obtain the maximum swimming speed of the character|
maxWalkSpeed(): number other
Obtain the maximum walking speed of the character|
maxWalkSpeedCrouched(): number other
Obtain the maximum crouching walking speed of character
meshPositionOffset(): Vector other
Obtain the offset of the mesh relative to the character coordinate points
meshRotationOffset(): Rotation other
Get the offset of mesh relative to character rotation
moveFacingDirection(): MoveFacingDirection other
Obtain the direction of the character's movement face|
movementDirection(): MovementDirection other
Get the positive direction of character motion|
opacity(): number other
Obtain single-layer transparency of the character
outOfWaterVerticalSpeed(): number other
Speed in vertical direction when leaving water
overheadUI(): UIWidget other
Interface for obtaining the name on the top of the character's head
physicsEnabled(): boolean
Get physical simulation status of character
ragdollEnabled(): boolean
Enable doll
rotateRate(): number other
Obtain the maximum turning speed of the character|
velocity(): Vector other
Get the current movement speed of the character
walkableFloorAngle(): number other
Get the maximum angle that character can walk|
nameDisplayDistance(): number other
Get the visible distance of the overhead display names of all characters in the current client.
nameVisible(): boolean other
Retrieve whether the overhead display names of all characters in the current client are visible.
click

Accessors ​

customTimeDilation(): number other
Expansion time velocity
player(): Player other
Player Object

Methods ​

addImpulse(vector: Vector, ignoreMass?: boolean): void other
When impulse is added, the force effect will be different with the same impulse value when the doll is in normal state|
addMovement(direction: Vector): void other
Add motion input along the given direction vector|
attachToSlot(gameObject: GameObject, slotName: NonHumanoidSlotType HumanoidSlotType): void other
Attach an object to the designated slot of the character character|
cancelHeadFollow(): void other
Cancel head tracking
changeState(stateType: CharacterStateType): void other
Change the status of character
clearDescription(appearance?: boolean, slotAndDecoration?: boolean): void other
Clear character appearance data|
detachAllFromSlot(param?: Object): void other
Separate all objects attached to the character slot|
detachFromSlot(gameObject: GameObject): void other
Separate the object from the slot
getCenterVertexByMorphName(morphName: string): Vector other
Real time acquisition of center vertex position through the head model MorphName
getCurrentState(): CharacterStateType other
Get the current status of the character
getDescription(): CharacterDescription other
Get character appearance data|
getSlotWorldPosition(slotName: HumanoidSlotType): Vector other
Obtain the world coordinates of the character slot|
getVertexArrayByMorphName(morphName: string): Vector[] other
Real time acquisition of all vertex positions through the head model MorphName
getVertexPosition(index: number): Vector other
Real-time acquisition of vertex position through vertex index of head model|
headFollow(target: null GameObject Vector): void other
Head tracking
jump(): void other
Make the character trigger a jump behavior
loadAnimation(assetId: string): Animation other
Load an animation resource for the character|
loadStance(assetId: string): Stance other
Load a base stance for the character|
loadSubStance(assetId: string): SubStance other
Load a secondary stance for the character
setCollisionShapeAndExtent(shapeType: CustomShapeType, collisionExtent: Vector): void other
Set collision bodies of different shapes and sizes for character
setDescription(data: string string[] CharacterDescription): void other
Set character appearance data|
setStateEnabled(characterStateType: CharacterStateType, enabled: boolean): void other
Set role status switch
swimUpDown(speed: number): void other
Make character float and dive in the water
syncDescription(appearance?: boolean, slotAndDecoration?: boolean): void other
Synchronize character appearance data|
click

Methods ​

setOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Add outline Effect
setPostProcessOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Add post-processing strokes

Properties ​


onDescriptionChange ​

• onDescriptionChange: MulticastDelegate<OnDescriptionChange> other

Commissioned changes in appearance loading details

Precautions

Execute the binding function when the appearance of the character object changes

Usage example: Drag the resource "1452135391161245756745773163910586945870060384586916183" into the priority loading bar. Create a script called 'Instance_Characters_OnDescriptionChange', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the character's appearance, prepares the player's appearance, and plays the idle hand effect. Add a function to delegate [character appearance Description Complete] to play the effect after the costume change is completed, and save the initial default appearance data of the character. Add a function to the delegate of character appearance Description Change to print the specific subitems and indexes of the current character appearance Description Change on the console. Press the keyboard "1" to reset to the default character appearance. Press keyboard "2" to modify the appearance of the character. Press keyboard "3" to synchronize the appearance of the character. Press the keyboard "4" to clear the character appearance. The code is as follows:

ts
@Component
export default class Example_Character_OnDescriptionChange extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character_OnDescriptionChange extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

onDescriptionComplete ​

• onDescriptionComplete: MulticastDelegate<OnDescriptionComplete> other

When the character appearance is loaded, call delegate

Precautions

Execute the binding function when the appearance of the character object is loaded

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, and run the game. Add a function to the delegate of [character appearance Loading Complete] to play the effect after the change. Press keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press the keyboard "4" to clear the character appearance. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of [character Dressing Complete]
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType:HumanoidSlotType.Hair});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of [character Dressing Complete]
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType:HumanoidSlotType.Hair});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

onEmergeFromWater ​

• onEmergeFromWater: MulticastDelegate<() => void> other

When the character swims up to the water surface in the swimming area, call delegate

Precautions

Execute the bind function when the character object swims up to the water surface in the swimming area

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Add a function to the delegate of [character reaches the water surface in the swimming area]
            myCharacter.onDescriptionComplete.add(() => {
                // jump
                myCharacter.changeState(CharacterStateType.Jumping);
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Add a function to the delegate of [character reaches the water surface in the swimming area]
            myCharacter.onDescriptionComplete.add(() => {
                // jump
                myCharacter.changeState(CharacterStateType.Jumping);
                }
            });
        }
    }
}

onStateChanged ​

• onStateChanged: MulticastDelegate<(prevState: CharacterStateType, currentState: CharacterStateType) => void>

Character status change callback Example usage: Press 0-9, Z, X, C, V to view and print

ts
@Component
export default class NewScript1 extends Script {
    private character: Character;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        Player.asyncGetLocalPlayer().then((player) => {
            this.character = player.character;
            this.character.onStateChanged.add((pre, curr)=>{
                console.log(`pre: ${pre} curr: ${curr}`);

            })
        });
      InputUtil.onKeyDown(Keys.Zero, ()=>{
            this.character.changeState(CharacterStateType.None);
        })
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.character.changeState(CharacterStateType.Running);
        })
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.character.changeState(CharacterStateType.Flying);
        })
        InputUtil.onKeyDown(Keys.Three, ()=>{
            this.character.changeState(CharacterStateType.Swimming);
        })
        InputUtil.onKeyDown(Keys.Four, ()=>{
            this.character.changeState(CharacterStateType.Jumping);
        })
        InputUtil.onKeyDown(Keys.Five, ()=>{
            this.character.changeState(CharacterStateType.Freefall);
        })
        InputUtil.onKeyDown(Keys.Six, ()=>{
            this.character.changeState(CharacterStateType.Ragdoll);
        })
        InputUtil.onKeyDown(Keys.Seven, ()=>{
            this.character.changeState(CharacterStateType.GettingUp);
        })
        InputUtil.onKeyDown(Keys.Eight, ()=>{
            this.character.changeState(CharacterStateType.Climbing);
        })
        InputUtil.onKeyDown(Keys.Nine, ()=>{
            this.character.changeState(CharacterStateType.Crouching);
        })
        InputUtil.onKeyDown(Keys.Z, ()=>{
            this.character.changeState(CharacterStateType.Pushed);
        })
        InputUtil.onKeyDown(Keys.X, ()=>{
            this.character.changeState(CharacterStateType.Landed);
        })
        InputUtil.onKeyDown(Keys.C, ()=>{
            this.character.changeState(CharacterStateType.Hit);
        })
        InputUtil.onKeyDown(Keys.V, ()=>{
            this.character.changeState(CharacterStateType.Dead);
        })
      InputUtil.onKeyDown(Keys.E, ()=>{
          console.log("currentState=="+this.character.getCurrentState());
        })
      InputUtil.onKeyDown(Keys.R, ()=>{
          this.character.setStateEnabled(CharacterStateType.Flying, false);
        })
    }
}
@Component
export default class NewScript1 extends Script {
    private character: Character;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        Player.asyncGetLocalPlayer().then((player) => {
            this.character = player.character;
            this.character.onStateChanged.add((pre, curr)=>{
                console.log(`pre: ${pre} curr: ${curr}`);

            })
        });
      InputUtil.onKeyDown(Keys.Zero, ()=>{
            this.character.changeState(CharacterStateType.None);
        })
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.character.changeState(CharacterStateType.Running);
        })
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.character.changeState(CharacterStateType.Flying);
        })
        InputUtil.onKeyDown(Keys.Three, ()=>{
            this.character.changeState(CharacterStateType.Swimming);
        })
        InputUtil.onKeyDown(Keys.Four, ()=>{
            this.character.changeState(CharacterStateType.Jumping);
        })
        InputUtil.onKeyDown(Keys.Five, ()=>{
            this.character.changeState(CharacterStateType.Freefall);
        })
        InputUtil.onKeyDown(Keys.Six, ()=>{
            this.character.changeState(CharacterStateType.Ragdoll);
        })
        InputUtil.onKeyDown(Keys.Seven, ()=>{
            this.character.changeState(CharacterStateType.GettingUp);
        })
        InputUtil.onKeyDown(Keys.Eight, ()=>{
            this.character.changeState(CharacterStateType.Climbing);
        })
        InputUtil.onKeyDown(Keys.Nine, ()=>{
            this.character.changeState(CharacterStateType.Crouching);
        })
        InputUtil.onKeyDown(Keys.Z, ()=>{
            this.character.changeState(CharacterStateType.Pushed);
        })
        InputUtil.onKeyDown(Keys.X, ()=>{
            this.character.changeState(CharacterStateType.Landed);
        })
        InputUtil.onKeyDown(Keys.C, ()=>{
            this.character.changeState(CharacterStateType.Hit);
        })
        InputUtil.onKeyDown(Keys.V, ()=>{
            this.character.changeState(CharacterStateType.Dead);
        })
      InputUtil.onKeyDown(Keys.E, ()=>{
          console.log("currentState=="+this.character.getCurrentState());
        })
      InputUtil.onKeyDown(Keys.R, ()=>{
          this.character.setStateEnabled(CharacterStateType.Flying, false);
        })
    }
}

Accessors ​


brakingDecelerationFlying ​

• get brakingDecelerationFlying(): number other

• set brakingDecelerationFlying(InBrakingDecelerationFlying): void other

Get character's flight brake rate

Usage example: drag the used asset: "5301120307" into the priority loading column. Create a script named "Example_BrakingDecelerationFlying", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", the character switches to flying, press the keyboard "2", the character accelerates by spraying, and modifies the flying brake speed. You will see the effect of the change of flight brake speed of the character during acceleration flight in the scene. The code is as follows:

ts
@Component
export default class Example_BrakingDecelerationFlying extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Load Jet Acceleration Animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 0;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: keyboard "1", switch the character to flight
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.switchToFlying();
            });
            // Add a button method: Press keyboard "2" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Two, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the flight animation and modify the flight speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxFlySpeed = 2000;
                    myCharacter.brakingDecelerationFlying = 5000;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore flight speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxFlySpeed = 500;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.addMovement(new Vector(0, 0, 5));
                    }, 1);
                }
                // Perform stop acceleration operation after 2 seconds
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxFlySpeed = 500;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 2000);
                    // Restore character's flight brake speed in 2.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationFlying = 300;
                    }, 2200);
            });
        }
    }
}
@Component
export default class Example_BrakingDecelerationFlying extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Load Jet Acceleration Animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 0;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: keyboard "1", switch the character to flight
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.switchToFlying();
            });
            // Add a button method: Press keyboard "2" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Two, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the flight animation and modify the flight speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxFlySpeed = 2000;
                    myCharacter.brakingDecelerationFlying = 5000;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore flight speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxFlySpeed = 500;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.addMovement(new Vector(0, 0, 5));
                    }, 1);
                }
                // Perform stop acceleration operation after 2 seconds
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxFlySpeed = 500;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 2000);
                    // Restore character's flight brake speed in 2.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationFlying = 300;
                    }, 2200);
            });
        }
    }
}

Returns ​

numberBrake rate< The default value is 2048.

Set character flight brake rate
When flying in the air, the character decelerates and does not apply acceleration.

Parameters ​

InBrakingDecelerationFlying numberUsage: Braking speed< br> range: (0,+∞)

brakingDecelerationSwimming ​

• get brakingDecelerationSwimming(): number other

• set brakingDecelerationSwimming(InBrakingDecelerationSwimming): void other

Get the character's swimming brake speed
The deceleration the character receives when moving in the swimming state.

Usage example: Drag the resource "5301120307" into the priority loading bar. Create a script named "Example_BrakingDecelerationSwimming", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate an arched Container in the scene and adapt it to the swimming area. Press keyboard "1" to switch roles and swim. Press "4" on the keyboard, and the character modifies the swimming brake speed and then performs jet acceleration. The effect of the character's swimming brake speed change that you can see. The code is as follows:

ts
@Component
export default class Example_BrakingDecelerationSwimming extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}
@Component
export default class Example_BrakingDecelerationSwimming extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}

Returns ​

numberBrake rate< The default value is 2048.

Set the character's swimming braking speed

Parameters ​

InBrakingDecelerationSwimming numberBraking speed< br> range: (0,+∞)

brakingDecelerationWalking ​

• get brakingDecelerationWalking(): number other

• set brakingDecelerationWalking(InBrakingDecelerationWalking): void other

Set the character walking brake rate
The walking brake speed refers to the braking deceleration of the character in the walking state. When a character stops moving or changes direction while walking, braking deceleration will affect the speed at which the character decelerates
A higher value causes the character to decelerate faster, while a lower value causes the character to decelerate more slowly.

Usage example: create a script named "Example_Braking", place it in the object bar, open the script, enter the following code to save, run the game, you will set the character's walking brake rate to the original 0.1, and see the effect of character's moving acceleration in the scene. The code is as follows:

ts
@Component
export default class Example_Braking extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_Braking extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

numberBraking speed during walking< The default value is 2048

Set the character walking brake rate

Precautions

It only takes effect when the enable brake friction groundFriction is enabled.

Parameters ​

InBrakingDecelerationWalking numberTravel brake rate
range: (0,+∞)

canStandOn ​

• get canStandOn(): boolean other

• set canStandOn(CanStepUpOn): void other

Get whether the character can be standing by other Player
True means that other character can stand on Player 'heads. False means that other characters cannot stand on the player's head.

Usage example: drag the used asset: "36851" into the priority loading column. Create a script named "Example_Character_CanStandOn", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate an NPC in the scene. Press keyboard "2" to turn on/off whether the character can be stood up. You can see that NPC switching can have different interaction effects with character after standing. The code is as follows:

ts
@Component
export default class Example_Character_CanStandOn extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character_CanStandOn extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

Returns ​

booleanCan it be stood up< Br>The default value is true.

Set whether the character can be stood up by other players.

Parameters ​

CanStepUpOn booleanCan it be stood up.

capsuleCorrectionEnabled ​

• get capsuleCorrectionEnabled(): boolean other

• set capsuleCorrectionEnabled(usedCapsuleCorrection): void other

Get whether the character is currently using capsule correction
True means that the size of the capsule is automatically calculated from the data in the application character editing. False represents the application of "capsuleHalfHeight" and "capsuleRadius" to set the size of the capsule body.

Usage example: drag the used asset: "36851" into the priority loading column. Create a script named 'Instance_Character_CapsuleCorrectEnabled', place it in the object bar, open the script, enter the following code to save, run the game, set character collision correction to true, which means character collisions will be consistent with character appearance. The code is as follows:

ts
@Component
export default class Example_Character_CapsuleCorrectionEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character_CapsuleCorrectionEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

Returns ​

booleanShould capsule correction be used< Br>The default value is true.

Set whether the character is currently using capsule correction

Parameters ​

usedCapsuleCorrection booleanShould capsule correction be used.

characterType ​

• get characterType(): CharacterType

What type of character is obtained
Character types are divided into basic humanoid, advanced humanoid, and quadrupedal types.

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

Returns ​

CharacterType

collisionExtent ​

• get collisionExtent(): Vector other

• set collisionExtent(extent): void other

Obtain the shape and size of the collision body of the package character
The size of the character collision box shape determines the size of the collision detection range when the character interacts with scene objects.

Usage example: Drag the resource "36851" into the priority loading bar. Create a script named 'Instance_Character_CollisionExtend', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '3', modify character collisions, and print the results. You will see the current character collision shape and size printed in the console. The code is as follows:

ts
@Component
export default class Example_Character_CollisionExtent extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character_CollisionExtent extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

Returns ​

VectorShape and size.

Set the shape and size of the wrapped character collision body

Parameters ​

extent VectorShape and size.

collisionShape ​

• get collisionShape(): CustomShapeType other

• set collisionShape(CustomShapeType): void other

Obtain the collision shape of characters (capsule shape, ball shape, box shape)
The size of the character's collision box shape determine the size of the detect collision range when the character interacts with scene objects. The sphere takes the minimum value of xyz, the capsule body radius takes the minimum value of xy, z is half length, and the box body xyz is half length, width, and height.

Usage example: drag the used asset: "36851" into the priority loading column. Create a script named 'Instance_Character_CollisionShape', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '3', modify character collisions, and print the results. You will see the printed current character collision shape in the console. The code is as follows:

ts
@Component
export default class Example_Character_CollisionShape extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character_CollisionShape extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

Returns ​

CustomShapeTypeCollision shape.

Set character collision shape (capsule shape, spherical shape, box shape)

Parameters ​

CustomShapeType CustomShapeTypeCollision shape.

collisionWithOtherCharacterEnabled ​

• get collisionWithOtherCharacterEnabled(): boolean other

• set collisionWithOtherCharacterEnabled(value): void

Gets whether the character can currently collision with other character.

Precautions

True means that the character can collision with other character, and false means that the character cannot collision with other character.

Usage example: drag the used asset: "36851" into the priority loading column. Create a script named "Example_Character_CollisionWithOtherCharacterEnabled", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate an NPC in the scene. Press "1" on the keyboard to turn on/off collision between NPC and other character. You can see the different interaction effects between NPC and character after turning off collision. The code is as follows:

ts
@Component
export default class Example_Character_CollisionWithOtherCharacterEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character_CollisionWithOtherCharacterEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

Returns ​

booleanCan there be collision< The default value is true.

Set whether the character can currently collide with other characters.

Parameters ​

value booleanCan there be collision.

complexMovementEnabled ​

• get complexMovementEnabled(): boolean

• set complexMovementEnabled(inValue): void

Whether to enable the complex mobile policy

Returns ​

booleanReturn whether the Boolean value is enabled for complex movement strategy.

Whether to enable the complex mobile policy
When the complex mobile strategy is enabled, the mobile logic that should be adopted will be determine according to the current mobile mode. It calculates the distance and direction that the character should move in the current frame according to the character's input and physical property (such as mass, friction, etc.)
Achieve advanced mobile logic and physical simulation of character, ensuring that character moves in the game world as expected, and interacts with the surrounding environment.

Parameters ​

inValue booleanTrue is on, false is off.

crouchedHeight ​

• get crouchedHeight(): number other

• set crouchedHeight(InCrouchedHeight): void other

Get the height of the collision box in the character crouch state.

Usage example: drag the used asset: "5483436851" into the priority loading column. Create a script named "Example_Character_CroutedHeight", place it in the object bar, open the script, enter the following code to save, run the game, you will generate grass and arch in the scene, add Trigger, and add delegate functions to achieve the effect of character squatting in the grass and standing up when leaving. Set the squat height to 100. You can see that the character can squat down and pass through the arch that cannot be passed before. The code is as follows:

ts
@Component
export default class Example_Character_CrouchedHeight extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}
@Component
export default class Example_Character_CrouchedHeight extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}

Returns ​

numberCollision box height< The default value is 60.

Set the height of the collision box when the character is crouch.

Parameters ​

InCrouchedHeight numberCollision box height< br> range: (0,+∞)

currentAnimation ​

• get currentAnimation(): Animation

The currently playing animation object

Returns ​

Animation

currentStance ​

• get currentStance(): Stance

Get the current playing basic pose

Usage example: drag the used asset: "23442316081" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", switch and play the anime basic male stance and anime basic female stance. Press keyboard "2" to stop playing the basic posture. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a anime male basic stance to the character
            let animeManStance = myCharacter.loadStance("234423");
            console.log("animeManStance assetId " + animeManStance.assetId);
            // Load a anime female basic stance for the character (default), and turn off aim offset
            let animeWomanStance = myCharacter.loadStance("216081");
            animeWomanStance.aimOffsetEnabled = false;
            console.log("animeWomanStance assetId " + animeWomanStance.assetId);
            // Add a button method: Press keyboard "1" to switch between playing 2D male basic poses and 2D female basic poses
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentStance == animeWomanStance) {
                    animeManStance.play();
                    // Enable aim offset
                    animeManStance.aimOffsetEnabled = true;
                } else {
                    animeWomanStance.play();
                    // Close aim offset
                    animeWomanStance.aimOffsetEnabled = false;
                }
            });
            // Add a button method: Press keyboard "2" to stop playing the basic posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentStance) {
                    myCharacter.currentStance.stop();
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a anime male basic stance to the character
            let animeManStance = myCharacter.loadStance("234423");
            console.log("animeManStance assetId " + animeManStance.assetId);
            // Load a anime female basic stance for the character (default), and turn off aim offset
            let animeWomanStance = myCharacter.loadStance("216081");
            animeWomanStance.aimOffsetEnabled = false;
            console.log("animeWomanStance assetId " + animeWomanStance.assetId);
            // Add a button method: Press keyboard "1" to switch between playing 2D male basic poses and 2D female basic poses
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentStance == animeWomanStance) {
                    animeManStance.play();
                    // Enable aim offset
                    animeManStance.aimOffsetEnabled = true;
                } else {
                    animeWomanStance.play();
                    // Close aim offset
                    animeWomanStance.aimOffsetEnabled = false;
                }
            });
            // Add a button method: Press keyboard "2" to stop playing the basic posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentStance) {
                    myCharacter.currentStance.stop();
                }
            });
        }
    }
}

Returns ​

StanceThe return value is the current base posture

currentSubStance ​

• get currentSubStance(): SubStance

Get the secondary stance currently playing, and the secondary stance type is SubStance

Usage example: drag the used asset: "9426114520" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save it, run the game, and load a aim stance with only upper body and a kicking stance with only lower body on the Player's character. Press the keyboard "1" to switch between playing aiming posture and kicking posture. Press "2" on the keyboard to stop playing stance. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load only upper aim stance for character
            let aimStance = myCharacter.loadSubStance("94261");
            aimStance.blendMode = StanceBlendMode.BlendUpper;
            console.log("aimStance assetId " + aimStance.assetId);
            // Load the character with only lower body kicking posture
            let kickStance = myCharacter.loadSubStance("14520");
            kickStance.blendMode = StanceBlendMode.BlendLower;
            console.log("kickStance assetId " + kickStance.assetId);
            // Add a key method: press the keyboard "1" to switch between aim stance and kicking stance
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentSubStance == aimStance) {
                    kickStance.play();
                } else {
                    aimStance.play();
                }
            });
            // Add a button method: Press keyboard "2" to stop playing posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentSubStance) {
                    myCharacter.currentSubStance.stop();
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load only upper aim stance for character
            let aimStance = myCharacter.loadSubStance("94261");
            aimStance.blendMode = StanceBlendMode.BlendUpper;
            console.log("aimStance assetId " + aimStance.assetId);
            // Load the character with only lower body kicking posture
            let kickStance = myCharacter.loadSubStance("14520");
            kickStance.blendMode = StanceBlendMode.BlendLower;
            console.log("kickStance assetId " + kickStance.assetId);
            // Add a key method: press the keyboard "1" to switch between aim stance and kicking stance
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentSubStance == aimStance) {
                    kickStance.play();
                } else {
                    aimStance.play();
                }
            });
            // Add a button method: Press keyboard "2" to stop playing posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentSubStance) {
                    myCharacter.currentSubStance.stop();
                }
            });
        }
    }
}

Returns ​

SubStanceReturn a second level posture type

description ​

• get description(): CharacterDescription other

Character appearance configuration
The return value is the CharacterDescription class. Calling the description variable can modify the appearance of a character, and the appearance parameters of the character can be changed. Please refer to the CharacterDescription class for details.

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Head: 1.5 times the size of the head
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Body type: 1.2 times the height
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Make up: 75674 for powder blusher
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Hair: 57731 for front hair and 63910 for back hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // 58694 for tops, 58700 for lower garment, 60384 for gloves and 58696 for shoes
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Head: 1.5 times the size of the head
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Body type: 1.2 times the height
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Make up: 75674 for powder blusher
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Hair: 57731 for front hair and 63910 for back hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // 58694 for tops, 58700 for lower garment, 60384 for gloves and 58696 for shoes
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

Returns ​

CharacterDescriptionThe return value is an object of type CharacterDescription.

displayName ​

• get displayName(): string

• set displayName(inName): void

Get character Name
The character name is displayed above the character by default.

Usage example: create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", and the name of the character in the scene changes. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let names = ["Cali", "Lily", "Emmie"];
            let index = 0;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Print the Guide and Name of Character Objects Controlled by Local Players
            console.log("My character: " + myPlayer.character.gameObjectId + " " + myPlayer.character.displayName);
            // Add a button method: Press keyboard "1" to switch the display name of the character
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.displayName = names[index % 3];
                index++;
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let names = ["Cali", "Lily", "Emmie"];
            let index = 0;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Print the Guide and Name of Character Objects Controlled by Local Players
            console.log("My character: " + myPlayer.character.gameObjectId + " " + myPlayer.character.displayName);
            // Add a button method: Press keyboard "1" to switch the display name of the character
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.displayName = names[index % 3];
                index++;
            });
        }
    }
}

Returns ​

stringCharacter name string

Set character Name
The name is a randomly initialized English name that can be changed according to one's own preferences.

Parameters ​

inName stringThe name of the character you want to change range: just set a reasonable name

driftControl ​

• get driftControl(): number other

• set driftControl(InAirControl): void other

Get the flexibility of character in the air
When the character is in the air, control the flexibility of horizontal movement; Range: 0~1, 0 means no control, 1 means full control according to the maximum ground movement rate

Usage example: create a script named "Example_DriftControl", place it in the object bar, open the script, enter the following code to save, run the game, and you will set the character's air control coefficient to 0.1. Press "1" on the keyboard, and the character will jump after setting the jumping height to 1000. You can see in the scene the effect that it is difficult for the character to control in the air when the fall speed threshold is exceeded. The code is as follows:

ts
@Component
export default class Example_DriftControl extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}
@Component
export default class Example_DriftControl extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}

Returns ​

numberAir flexibility< Br>The default value is 0.2.

Set the flexibility of the character in the air

Parameters ​

InAirControl numberBrake rate< br> range: [0,1]

forceUpdateMovement ​

• set forceUpdateMovement(value): void other

Force update Move

Precautions

Whether the character is currently enable to force update movement. True indicates that the character will be passively displaced due to collision, and false indicates that the character will not be passively displaced due to collision.

Usage example: drag the used asset: "197386" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, you will generate a cube in the scene, and move it left and right in onUpdate, press the keyboard "1", enable/disable the character [Force update Movement], and see the cube's pushing effect on the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // Declare variables
    cube: GameObject;
    stride: Vector;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            this.useUpdate = true;
            // Move step: Y axis unit distance
            this.stride = new Vector(-2, 0, 0);
            // Generate a cube in front and move it left and right in onUpdate
            let spawnTransform = new Transform(new Vector(300, 0, 0), Rotation.zero, Vector.one);
            this.cube = GameObject.spawn("197386",{transform: spawnTransform});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", enable/disable [Force update movement]
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.forceUpdateMovement = !myCharacter.forceUpdateMovement;
                Console. log ("Whether the current character forces update movement:"+myCharacter. forceUpdateMovement);
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // When the cube is not empty, update the world coordinates of the cube every frame by step (move left and right)
            if(this.cube) {
                this.cube.worldTransform.position = this.cube.worldTransform.position.add(this.stride);
                // When the absolute value of the world coordinate on the y-axis of the cube exceeds 1000, the step size is reversed
                if(Math.abs(this.cube.worldTransform.position.x) > 500) {
                    this.stride.multiply(-1);
                }
            }
        }
    }
}
@Component
export default class Example_Character extends Script {
    // Declare variables
    cube: GameObject;
    stride: Vector;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            this.useUpdate = true;
            // Move step: Y axis unit distance
            this.stride = new Vector(-2, 0, 0);
            // Generate a cube in front and move it left and right in onUpdate
            let spawnTransform = new Transform(new Vector(300, 0, 0), Rotation.zero, Vector.one);
            this.cube = GameObject.spawn("197386",{transform: spawnTransform});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", enable/disable [Force update movement]
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.forceUpdateMovement = !myCharacter.forceUpdateMovement;
                Console. log ("Whether the current character forces update movement:"+myCharacter. forceUpdateMovement);
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // When the cube is not empty, update the world coordinates of the cube every frame by step (move left and right)
            if(this.cube) {
                this.cube.worldTransform.position = this.cube.worldTransform.position.add(this.stride);
                // When the absolute value of the world coordinate on the y-axis of the cube exceeds 1000, the step size is reversed
                if(Math.abs(this.cube.worldTransform.position.x) > 500) {
                    this.stride.multiply(-1);
                }
            }
        }
    }
}

Parameters ​

value booleanTrue is enabled, false is disabled to force update movement< Br>The default value is true

gravityScale ​

• get gravityScale(): number other

• set gravityScale(newGravityScale): void other

Obtain the magnification of gravity
For characters, gravity will be multiplied by this value. The range is from 0 to 10, and values that are too large or too small will be restricted.

Example usage: Create a script called "Instance_Character_GravityScale", place it in the object bar, open the script, enter the following code to save, run the game, and you will set the character's gravity factor to 10. Press "1" on the keyboard, and the character will jump after setting the jumping height to 1000. You can see the effect of character fall under ten times of gravity in the scene. The code is as follows:

ts
@Component
export default class Example_Character_GravityScale extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}
@Component
export default class Example_Character_GravityScale extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}

Returns ​

numberMagnification< Br>The default value is 1.0.

Set the magnification of gravity

Parameters ​

newGravityScale numberBraking speed< br> range: (0,10]

groundFriction ​

• get groundFriction(): number other

• set groundFriction(inGroundFriction): void other

Obtain ground friction force

Usage example: create a script named "Example_GroundFriction", place it in the object bar, open the script, enter the following code to save, run the game, you will set the character ground friction to 1, press the keyboard "1", switch the source of character friction. In the scene, you can see the effect that character moves faster. The code is as follows:

ts
@Component
export default class Example_GroundFriction extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The walking braking speed is 0.1 times faster than before
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a button method: Press keyboard "1" to enable/disable ground friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_GroundFriction extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The walking braking speed is 0.1 times faster than before
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a button method: Press keyboard "1" to enable/disable ground friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

numberFriction force< Br>The default value is 8.

Set ground friction force

Precautions

The magnitude of friction experienced by the character on the ground. This value does not take effect when the individual brake friction groundFriction is activated.

Parameters ​

inGroundFrictionnumber

groundFrictionEnabled ​

• get groundFrictionEnabled(): boolean other

• set groundFrictionEnabled(used): void other

Obtain separate brake friction status
When it is turned on, the walking brake rate is used to calculate the friction effect. When it is not turned on, the ground friction is used to calculate the friction effect.

Usage example: create a script named "Example_GroundFriction", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", and switch the source of character friction. And you can see the effect of character's movement accelerating changes in the scene. The code is as follows:

ts
@Component
export default class Example_GroundFriction extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The walking braking speed is 0.1 times faster than before
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a button method: Press keyboard "1" to enable/disable ground friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_GroundFriction extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The walking braking speed is 0.1 times faster than before
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a button method: Press keyboard "1" to enable/disable ground friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

booleanWhether to open brake friction, true means open, false means closed< The default value is false.

Set separate brake friction state
When the character is in motion, brake friction is used to let the character stop moving (when there is no acceleration).

Parameters ​

used booleanBrake friction.

horizontalBrakingDecelerationFalling ​

• get horizontalBrakingDecelerationFalling(): number other

• set horizontalBrakingDecelerationFalling(InBrakingDecelerationFalling): void other

Obtain the character's descent braking rate
The deceleration the character receives when moving in the fall state.

Example usage: Create a script called "Instance-HorizontalBrakingDecelerationFalling", place it in the object bar, open the script, enter the following code to save, run the game, and you will set the character's descent braking speed to 10. Press "1" on the keyboard, and the character will jump after setting the jump height to 1000. You can see the fall acceleration effect slower than normal in the scene. The code is as follows:

ts
@Component
export default class Example_HorizontalBrakingDecelerationFalling extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}
@Component
export default class Example_HorizontalBrakingDecelerationFalling extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}

Returns ​

numberBraking speed< The default value is 500.

Set the character's descent braking rate

Parameters ​

InBrakingDecelerationFalling numberBraking speed< br> range: (0,+∞)

isCrouching ​

• get isCrouching(): boolean other

Get whether the character is squatting

Usage example: Drag the resource "5483436851" into the priority loading bar. Create a script called 'Instance_Character_isCRouting', place it in the object bar, open the script, enter the following code to save, run the game, and you will generate grass and arches in the scene and add triggers. Seeing the character squatting in the grass, leaving the standing effect, and seeing the printed character's current squatting state on the console. The code is as follows:

ts
@Component
export default class Example_Character_IsCrouching extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}
@Component
export default class Example_Character_IsCrouching extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}

Returns ​

booleanSquatting state.

isDescriptionReady ​

• get isDescriptionReady(): boolean other

Get whether the current character appearance is ready
When entering the scene or the character has not yet loaded the appearance clothes, etc., isDescriptionReady is set to false, and it becomes true after complete loading.

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

Returns ​

booleanTrue means ready, false means not ready.

isJumping ​

• get isJumping(): boolean other

Get whether the character is jumping or not

Example usage: Create a script called "Instance_Character_SJumping", place it in the object bar, open the script, enter the following code to save, run the game, set the maximum jumping height of the character to 300, and the highest triple jump. Press keyboard "1" to jump the character. Press the keyboard "2" to enable/disable the jumping ability. You will see the effect of disable the jumping ability of the character in the scene. The code is as follows:

ts
@Component
export default class Example_Character_IsJumping extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}
@Component
export default class Example_Character_IsJumping extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}

Returns ​

booleanJumping state. True means jumping, false means not jumping.

isMoving ​

• get isMoving(): boolean other

Get whether the character is moving

Usage example: create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save it, and run the game. If the character is moving, you will see the printed character moving speed in the console. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

booleanIs the Boolean value being moved. True indicates that the character is moving and the speed is not 0. False means no movement, and the character speed is 0.

jumpMaxCount ​

• get jumpMaxCount(): number other

• set jumpMaxCount(InJumpMaxCount): void other

Get the maximum number of hops a character can make
The maximum number of jumps that a character can perform.

Usage example: create a script named "Example_Character_jumpMaxCount", place it in the object bar, open the script, enter the following code to save, run the game and set the maximum jump height of the character to 300, and the maximum jump height to three consecutive jumps. Press keyboard "1" to jump the character. Press keyboard "2" to enable/disable jumping ability. You will see the effect of disabling the jumping ability of the character in the scene. The code is as follows:

ts
@Component
export default class Example_Character_jumpMaxCount extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}
@Component
export default class Example_Character_jumpMaxCount extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}

Returns ​

numberJump frequency.

Set the maximum number of jumps for character

Parameters ​

InJumpMaxCount numberJump frequency< br> range: (0,+∞)

maxAcceleration ​

• get maxAcceleration(): number other

• set maxAcceleration(InMaxAcceleration): void other

Obtain the maximum acceleration of the character
The maximum acceleration that a character can achieve when moving

Example usage: Create a script called "Instance_Character_SaxAcceleration", place it in the object bar, open the script, enter the following code to save, run the game, you will set the maximum acceleration of the character to 0.1 times the original, and see the effect of slowing down the character's acceleration in the scene. The code is as follows:

ts
@Component
export default class Example_Character_MaxAcceleration extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_Character_MaxAcceleration extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

numberMaximum acceleration< The default value is 2048.

Set the maximum acceleration of the character

Parameters ​

InMaxAcceleration numberMaximum acceleration< br> range: (0,+∞)

maxFallingSpeed ​

• get maxFallingSpeed(): number other

• set maxFallingSpeed(speed): void other

Set the maximum descent speed of the character
The maximum movement speed that a character can reach when moving in a falling state

Example usage: Create a script called "InstancenMaxFallingspeed", place it in the object bar, open the script, enter the following code to save, run the game, and you will set the maximum falling speed of the character to 1024. Press "1" on the keyboard, and the character will jump after setting the jumping height to 1000. You can see the effect of fall faster than normal in the scene. The code is as follows:

ts
@Component
export default class Example_MaxFallingSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}
@Component
export default class Example_MaxFallingSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum falling speed is 1024
            myCharacter.maxFallingSpeed = 1024;
            // Fall brake rate is 10
            myCharacter.horizontalBrakingDecelerationFalling = 10;
            // Control the falling process at 0.1 times the ground movement rate
            myCharacter.driftControl = 0.1;
            // 10 times gravity
            myCharacter.gravityScale = 10;
            // Add a button method: Press keyboard "1" and set the character's jumping height to 1000 before jumping.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxJumpHeight = 1000;
                myCharacter.jump();
            });
        }
    }
}

Returns ​

numberFall speed< The default value is 2048.

Set the maximum descent speed of the character

Parameters ​

speed numberFall speed< br> range: (0,+∞)

maxFlySpeed ​

• get maxFlySpeed(): number other

• set maxFlySpeed(InMaxFlySpeed): void other

Obtain the maximum flight speed of the character
The maximum movement speed that a character can reach when moving in flight

Usage example: drag the used asset: "5301120307" into the priority loading column. Create a script named "Example_MaxFlySpeed", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", the character switches to flight, and press the keyboard "2", the character accelerates by spraying. You will see the effect of the character's maximum flight speed changing during acceleration in the scene. The code is as follows:

ts
@Component
export default class Example_MaxFlySpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Load Jet Acceleration Animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 0;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a button method: Press keyboard "1" to switch the character to flight
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.switchToFlying();
            });
            // Add a button method: Press keyboard "2" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Two, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the flight animation and modify the flight speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxFlySpeed = 2000;
                    myCharacter.brakingDecelerationFlying = 5000;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore flight speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxFlySpeed = 500;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.addMovement(new Vector(0, 0, 5));
                    }, 1);
                }
                // Perform stop acceleration operation after 2 seconds
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxFlySpeed = 500;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 2000);
                    // Restore character's flight brake speed in 2.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationFlying = 300;
                    }, 2200);
            });
        }
    }
}
@Component
export default class Example_MaxFlySpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Load Jet Acceleration Animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 0;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a button method: Press keyboard "1" to switch the character to flight
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.switchToFlying();
            });
            // Add a button method: Press keyboard "2" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Two, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the flight animation and modify the flight speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxFlySpeed = 2000;
                    myCharacter.brakingDecelerationFlying = 5000;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore flight speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxFlySpeed = 500;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.addMovement(new Vector(0, 0, 5));
                    }, 1);
                }
                // Perform stop acceleration operation after 2 seconds
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxFlySpeed = 500;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 2000);
                    // Restore character's flight brake speed in 2.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationFlying = 300;
                    }, 2200);
            });
        }
    }
}

Returns ​

numberMaximum flight speed< Br>The default value is 800

Set the maximum flying speed of character

Parameters ​

InMaxFlySpeed numberMaximum flight speed< br> range: (0,+∞)

maxJumpHeight ​

• get maxJumpHeight(): number other

• set maxJumpHeight(InMaxJumpHeight): void other

Get the maximum jump height of character
The distance from the position to the highest position when the character jumps. This value is affected by gravity.

Usage example: create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, set the maximum height of the character jump to 300, and the maximum triple jump. Press the keyboard "1", and the character jumps. Press keyboard "2" to enable/disable jumping ability. You will see the effect of disable the jumping ability of the character in the scene. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a key method: press the keyboard "1", and the character jumps.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}

Returns ​

numberJump height< Br>The default value is 50.0.

Set the maximum jump height of character

Parameters ​

InMaxJumpHeight numberBraking speed< br> range: (0,+∞)

maxStepHeight ​

• get maxStepHeight(): number other

• set maxStepHeight(InMaxStepHeight): void other

Obtain the maximum height that the character can cross
When a character crosses a step, the maximum height of the step, which is greater than or equal to the height, cannot be crossed by a character.

Usage example: drag the used asset: "7667197386" into the priority loading column. Create a script named 'InstancenMaxStepHeight', place it in the object bar, open the script, enter the following code to save, run the game, and you will create 5 cubes of different heights in the scene: 10, 20, 40, 80, 160. Press "1" on the keyboard, and the maximum span height of the character can be increased by 10. Press "2" on the keyboard, and the maximum span height of the character can be reduced by 10. You will see the effect of height change that character can span most. The code is as follows:

ts
@Component
export default class Example_MaxStepHeight extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the server side
         if(SystemUtil.isServer()) {
            // Create 5 cubes of different heights: 10, 20, 40, 80, 160
            let cubeHeight = [10, 20, 40, 80, 160];
            for (let i = 0;
i < cubeHeight.length;
i++) {
                GameObject.spawn("197386",{transform: new Transform(new Vector(250 * i, -500, 0), Rotation.zero, new Vector(2, 2, cubeHeight[i] / 100))});
            }
            // Create 5 cones with different slopes: 1, 30, 45, 60, 89
            let coneAngle = [1, 30, 45, 60, 89];
            for (let i = 0;
i < coneAngle.length;
i++) {
                console.log("1111");
                GameObject.spawn("7667",{transform: new Transform(new Vector(250 * i, 500, 0), Rotation.zero, new Vector(2, 2, Math.tan(coneAngle[i] * Math.PI / 180)))});
            }
         }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", and the maximum span height of the character increases by 10
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxStepHeight += 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "2" on the keyboard, and the maximum span height of the character will be reduced by 10
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.maxStepHeight -= 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "3" on the keyboard, and the maximum walking angle of the character increases by 5
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.walkableFloorAngle += 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
            // Add a key method: press "4" on the keyboard, and the maximum walking angle of the character decreases by 5
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.walkableFloorAngle -= 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
        }
    }
}
@Component
export default class Example_MaxStepHeight extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the server side
         if(SystemUtil.isServer()) {
            // Create 5 cubes of different heights: 10, 20, 40, 80, 160
            let cubeHeight = [10, 20, 40, 80, 160];
            for (let i = 0;
i < cubeHeight.length;
i++) {
                GameObject.spawn("197386",{transform: new Transform(new Vector(250 * i, -500, 0), Rotation.zero, new Vector(2, 2, cubeHeight[i] / 100))});
            }
            // Create 5 cones with different slopes: 1, 30, 45, 60, 89
            let coneAngle = [1, 30, 45, 60, 89];
            for (let i = 0;
i < coneAngle.length;
i++) {
                console.log("1111");
                GameObject.spawn("7667",{transform: new Transform(new Vector(250 * i, 500, 0), Rotation.zero, new Vector(2, 2, Math.tan(coneAngle[i] * Math.PI / 180)))});
            }
         }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", and the maximum span height of the character increases by 10
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxStepHeight += 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "2" on the keyboard, and the maximum span height of the character will be reduced by 10
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.maxStepHeight -= 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "3" on the keyboard, and the maximum walking angle of the character increases by 5
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.walkableFloorAngle += 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
            // Add a key method: press "4" on the keyboard, and the maximum walking angle of the character decreases by 5
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.walkableFloorAngle -= 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
        }
    }
}

Returns ​

numberThe maximum height that can be crossed< The default value is 45.

Set the maximum height that a character can cross

Parameters ​

InMaxStepHeight numberThe maximum span height is height< br> range: (0,+∞)

maxSwimSpeed ​

• get maxSwimSpeed(): number other

• set maxSwimSpeed(InMaxSwimSpeed): void other

Obtain the maximum swimming speed of the character
The maximum movement speed that a character can achieve while swimming.

Usage example: drag the used asset: "5301120307" into the priority loading column. Create a script called 'InstancenMaxSwimSpeed', place it in the object bar, open the script, enter the following code to save, run the game, and you will generate an arched container in the scene and adapt it to the swimming area. Press keyboard "1" to switch roles and swim. Press "4" on the keyboard, and the character will modify the maximum swimming speed for jet acceleration. You can see the effect of the maximum swimming speed change of the character. The code is as follows:

ts
@Component
export default class Example_MaxSwimSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}
@Component
export default class Example_MaxSwimSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}

Returns ​

numberMaximum swimming speed< The default value is 300

Set the maximum swimming speed for the character

Parameters ​

InMaxSwimSpeed numberMaximum swimming speed< br> range: (0,+∞)

maxWalkSpeed ​

• get maxWalkSpeed(): number other

• set maxWalkSpeed(InMaxWalkSpeed): void other

Obtain the maximum walking speed of the character
When the character moves, it does not directly become the maximum speed, but gradually increases with the input or other control. The maximum walking speed is the maximum speed that the character can reach
It is also the maximum lateral velocity when falling.

Usage example: create a script named "Example_MaxWalkSpeed", place it in the object bar, open the script, enter the following code to save, run the game, you will set the maximum walking speed of the character to twice the original speed, and see the effect that the maximum moving speed of the character becomes faster in the scene. The code is as follows:

ts
@Component
export default class Example_MaxWalkSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_MaxWalkSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

numberThe floating point number for the maximum walking speed of the character< The default value is 450

Set the maximum walking speed of the character

Parameters ​

InMaxWalkSpeed numberMaximum walking speed
range: (0,+∞)

maxWalkSpeedCrouched ​

• get maxWalkSpeedCrouched(): number other

• set maxWalkSpeedCrouched(maxSpeed): void other

Obtain the maximum crouching walking speed of character

Precautions

The maximum movement speed that a character can reach when moving in the crouch state

Usage example: drag the used asset: "5483436851" into the priority loading column. Create a script called 'InstancenMaxWalkSpeedCrouched', place it in the object bar, open the script, enter the following code to save, run the game, you will generate grass and arches in the scene and add triggers, add delegate functions to achieve the effect of the character squatting in the grass and standing up when leaving. Set the maximum movement speed when squatting on the ground to 100. You can see the effect of character's walking speed slowing down after squatting down. The code is as follows:

ts
@Component
export default class Example_MaxWalkSpeedCrouched extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}
@Component
export default class Example_MaxWalkSpeedCrouched extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate grass and arches
            GameObject.spawn("54834",{transform: new Transform(new Vector(300, 0, 0), Rotation.zero, new Vector(2, 2, 2))});
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Generate Trigger and add delegate function: enter the character of Trigger, squat down, leave the Trigger and stand up
            let tri = GameObject.spawn("Trigger",{transform: new Transform(new Vector(300, 0, 50), Rotation.zero, new Vector(2, 2, 1))}) as Trigger;
            tri.onEnter.add((character: Character) => {
                character.crouch(true);
                setTimeout(() => {
                    Console. log ("current character crouch"+character. isCrouching);
                }, 500);
            });
            tri.onLeave.add((character: Character) => {
                character.crouch(false);
                Console. log ("current character crouch"+character. isCrouching);
            });
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum movement speed when squatting on the ground is 100
            myCharacter.maxWalkSpeedCrouched = 100;
            // Height after crouch is 100
            myCharacter.crouchedHeight = 100;
            // Add a key method: press "1" on the keyboard to enable/disable the crouch ability
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.crouchEnabled = !myCharacter.crouchEnabled;
                Console. log ("Can the current character crouch"+myCharacter. routhEnabled);
            });
        }
    }
}

Returns ​

numberMaximum crouching walking speed< The default value is: 100

Set the maximum crouching walking speed of the character

Precautions

The maximum movement speed that a character can reach when moving in the crouch state

Parameters ​

maxSpeed numberMaximum crouching walking speed
range: (0,+∞)

meshPositionOffset ​

• get meshPositionOffset(): Vector other

• set meshPositionOffset(offset): void other

Obtain the offset of the mesh relative to the character coordinate points

Returns ​

VectorThe offset of mesh relative to the character coordinate point

Set the offset of the mesh relative to the character coordinate points

Parameters ​

offsetVector

meshRotationOffset ​

• get meshRotationOffset(): Rotation other

• set meshRotationOffset(offset): void other

Get the offset of mesh relative to character rotation

Returns ​

RotationThe offset of mesh relative to the character coordinate point

Set the offset of mesh relative to the rotation of character

Parameters ​

offsetRotation

moveFacingDirection ​

• get moveFacingDirection(): MoveFacingDirection other

• set moveFacingDirection(InMoveFacingDirection): void other

Obtain the direction of the character's movement face
The direction the character model faces when moving:\

  1. Always facing the direction of movement: The protagonist model always faces the direction of movement\
  2. Always facing in a fixed direction: The protagonist model always faces in a fixed direction\
  3. Always facing the direction of the controller: The protagonist model always faces the direction of the controller

Example usage: Create a script called "Instance_Character_SoveFacingDirection", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", switch the character's motion direction. You will see the effect of different movement directions of the character in the scene and see the printed motion axis and direction of the current character on the console. The code is as follows:

ts
@Component
export default class Example_Character_MoveFacingDirection extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set the fixed axis direction
            myCharacter.movementAxisDirection = new Vector(1, 0, 0);
            // Print the motion axis and facing direction of the current character
            Console. log ("The moving face of the current character faces the direction"+MoveFacingDirection [myCharacter. moveFacingDirection]);
            Console. log ("the positive direction according to which the current character moves"+MovementDirection [myCharacter. movementDirection]);
            // Add a button method: Press keyboard "1" to switch the direction of the character's movement face
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.moveFacingDirection = (myCharacter.moveFacingDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
            });
            // Add a button method: Press keyboard "2" to switch the forward direction of the character's movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.movementDirection = (myCharacter.movementDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
                if(myCharacter.movementDirection == 0) {
                    Console.log ("Current character's motion"+MoveFacingDirection [myCharacter. movFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]+"Fixed axis direction"+myCharacter. movementAxisDirection);
                }
            });
        }
    }
}
@Component
export default class Example_Character_MoveFacingDirection extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set the fixed axis direction
            myCharacter.movementAxisDirection = new Vector(1, 0, 0);
            // Print the motion axis and facing direction of the current character
            Console. log ("The moving face of the current character faces the direction"+MoveFacingDirection [myCharacter. moveFacingDirection]);
            Console. log ("the positive direction according to which the current character moves"+MovementDirection [myCharacter. movementDirection]);
            // Add a button method: Press keyboard "1" to switch the direction of the character's movement face
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.moveFacingDirection = (myCharacter.moveFacingDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
            });
            // Add a button method: Press keyboard "2" to switch the forward direction of the character's movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.movementDirection = (myCharacter.movementDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
                if(myCharacter.movementDirection == 0) {
                    Console.log ("Current character's motion"+MoveFacingDirection [myCharacter. movFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]+"Fixed axis direction"+myCharacter. movementAxisDirection);
                }
            });
        }
    }
}

Returns ​

MoveFacingDirectionList values facing the direction.

Set the character to face the direction when moving.

Parameters ​

InMoveFacingDirection MoveFacingDirectionFacing the direction.

movementDirection ​

• get movementDirection(): MovementDirection other

• set movementDirection(InMovementDirection): void other

Get the positive direction of character motion
The positive direction based on which the character moves\

  1. The direction of the controller is based on the controller coordinate system as the axis; \
  2. If it is a fixed axis direction, take the movementAxisDirection in the world coordinate system as the axis; \
  3. If it is the direction of the line of sight, use the camera coordinate system as the axis. When there is no Z-axis rotation in the player's camera, the controller direction and line of sight effect are consistent, and the controller direction and line of sight effect of humanoid objects are always consistent.

Usage example: create a script named "Example_Character_MovementDirection", place it in the object bar, open the script, enter the following code to save, run the game, press "2" on the keyboard, and switch the positive direction according to which the character moves. You will see the effect of different movements of the character in the scene based on the forward direction, and on the console, you will see the printed motion axis and forward direction of the current character. The code is as follows:

ts
@Component
export default class Example_Character_MovementDirection extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set the fixed axis direction
            myCharacter.movementAxisDirection = new Vector(1, 0, 0);
            // Print the motion axis and facing direction of the current character
            Console. log ("The moving face of the current character faces the direction"+MoveFacingDirection [myCharacter. moveFacingDirection]);
            Console. log ("the positive direction according to which the current character moves"+MovementDirection [myCharacter. movementDirection]);
            // Add a button method: Press keyboard "1" to switch the direction of the character's movement face
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.moveFacingDirection = (myCharacter.moveFacingDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
            });
            // Add a button method: Press keyboard "2" to switch the forward direction of the character's movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.movementDirection = (myCharacter.movementDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
                if(myCharacter.movementDirection == 0) {
                    Console.log ("Current character's motion"+MoveFacingDirection [myCharacter. movFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]+"Fixed axis direction"+myCharacter. movementAxisDirection);
                }
            });
        }
    }
}
@Component
export default class Example_Character_MovementDirection extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set the fixed axis direction
            myCharacter.movementAxisDirection = new Vector(1, 0, 0);
            // Print the motion axis and facing direction of the current character
            Console. log ("The moving face of the current character faces the direction"+MoveFacingDirection [myCharacter. moveFacingDirection]);
            Console. log ("the positive direction according to which the current character moves"+MovementDirection [myCharacter. movementDirection]);
            // Add a button method: Press keyboard "1" to switch the direction of the character's movement face
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.moveFacingDirection = (myCharacter.moveFacingDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
            });
            // Add a button method: Press keyboard "2" to switch the forward direction of the character's movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.movementDirection = (myCharacter.movementDirection + 1) % 3;
                Console.log ("Motion of the current character"+MoveFacingDirection [myCharacter. moveFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]);
                if(myCharacter.movementDirection == 0) {
                    Console.log ("Current character's motion"+MoveFacingDirection [myCharacter. movFacingDirection]+"+"+MovementDirection [myCharacter. movementDirection]+"Fixed axis direction"+myCharacter. movementAxisDirection);
                }
            });
        }
    }
}

Returns ​

MovementDirectionPositive direction of movement.

Set the positive direction of character movement

Parameters ​

InMovementDirection MovementDirectionPositive direction of movement.

opacity ​

• get opacity(): number other

• set opacity(value): void other

Obtain single-layer transparency of the character

Returns ​

numberObtain transparency

Set character single layer transparency

Parameters ​

value numberUsage: Transparency [0,1]

outOfWaterVerticalSpeed ​

• get outOfWaterVerticalSpeed(): number other

• set outOfWaterVerticalSpeed(value): void other

Speed in vertical direction when leaving water

Usage example: drag the used asset: "5301120307" into the priority loading column. Create a script named "Example_OutOfWaterVerticalSpeed", place it in the object bar, open the script, enter the following code to save, run the game, and set the character to jump out of the water with a vertical speed of 100. Generate arched containers in the scene and adapt them to the swimming area. Press and hold the keyboard "2", and the character floats up. You can see the effect of the character reaching the water surface and jumping out. The code is as follows:

ts
@Component
export default class Example_OutOfWaterVerticalSpeed  extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}
@Component
export default class Example_OutOfWaterVerticalSpeed  extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set swimming property
            myCharacter.canJumpOutOfWater = true;
            myCharacter.outOfWaterVerticalSpeed = 100;
            // Load accelerated animation
            let boostAnimation = myCharacter.loadAnimation("53011");
            boostAnimation.loop = 10;
            let isBoost = false
            // Loading upward posture
            let boostStance = myCharacter.loadSubStance("20307");
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUp(10);
            });
            // Add a button method: Press and hold the keyboard "3" to dive the character
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimDown(10);
            });
            // Add a button method: Press keyboard "4" to accelerate the character's jet
            InputUtil.onKeyDown(Keys.Four, () => {
                if(isBoost) return;
                let boost_interval = 0;
                if(myCharacter.isMoving) {
                    // Play the swimming animation and modify the swimming speed and brake speed
                    boostAnimation.play();
                    myCharacter.maxSwimSpeed = 600;
                    myCharacter.brakingDecelerationSwimming = 4096;
                    // Set the acceleration cycle, and check whether the character moves every frame. When the character stops moving, execute the stop acceleration operation: stop animation, clear stance, restore swimming speed, clear the acceleration cycle
                    boost_interval = setInterval(() => {
                        if(!myCharacter.isMoving) {
                            isBoost = false;
                            clearInterval(boost_interval);
                            myCharacter.maxSwimSpeed = 300;
                            boostAnimation.stop();
                            boostStance.stop();
                        }
                    }, 1);
                // If the current character is still, change the character to an upward stance, set the acceleration cycle, and increase 5 units per frame
                } else {
                    boostStance.play();
                    boost_interval = setInterval(() => {
                        myCharacter.swimUp(1)
                    }, 1);
                }
                // Perform stop acceleration operation after 1 second
                    setTimeout(() => {
                        isBoost = false;
                        clearInterval(boost_interval);
                        myCharacter.maxSwimSpeed = 300;
                        boostAnimation.stop();
                        boostStance.stop();
                    }, 1000);
                    // Restore the character's swimming brake speed in 1.2 seconds
                    setTimeout(() => {
                        myCharacter.brakingDecelerationSwimming = 4096
                    }, 1200);
            });
        }
    }
}

Returns ​

number

Speed in vertical direction when leaving water

Parameters ​

value numberWater output speed< br> range: (0,+∞)

overheadUI ​

• get overheadUI(): UIWidget other

Interface for obtaining the name on the top of the character's head

Example usage: Create a script named "Instance_Character", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1" to hide/display the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1" to hide/show the overhead UI
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.overheadUI.getVisibility() == true) {
                    myCharacter.overheadUI.setVisibility(PropertyStatus.Off);
                } else {
                    myCharacter.overheadUI.setVisibility(PropertyStatus.On);
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1" to hide/show the overhead UI
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.overheadUI.getVisibility() == true) {
                    myCharacter.overheadUI.setVisibility(PropertyStatus.Off);
                } else {
                    myCharacter.overheadUI.setVisibility(PropertyStatus.On);
                }
            });
        }
    }
}

Returns ​

UIWidgetHead mounted UIWidget object

physicsEnabled ​

• get physicsEnabled(): boolean

• set physicsEnabled(value): void

Get physical simulation status of character

Returns ​

booleanWhether physical simulation is enabled for the current character< The default value is false.

Set character physical simulation state

Parameters ​

value booleanUsage: Whether to enable character physical simulation.

ragdollEnabled ​

• get ragdollEnabled(): boolean

• set ragdollEnabled(value): void other

Enable doll

Precautions

Is the character currently in ragdoll state. True means use, and false means disable.

Usage example: Drag the resource "27693" into the priority loading bar. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate a circular black hole effect in the scene. If the distance between the character and the center of the black hole is less than 300 and the character has not turned on the doll, move the character towards the center. If the distance between the character and the center of the black hole is less than 50, turn on the doll. You can see the different effects when the character switches the doll. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Generate a black hole effect to play circularly
            EffectService.playAtPosition("27693", new Vector(500, 0, 50), {loopCount: 0});
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the distance between the character and the center of the black hole is less than 300 and the character has not turned on the doll, move the character towards the center
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 300 && !myCharacter.ragdollEnabled) {
                let dir = new Vector(500, 0, 50).subtract(myCharacter.worldTransform.position).normalize();
                myCharacter.addMovement(new Vector(dir.x, dir.y, 0));
            }
            // If the distance between the character and the center of the black hole is less than 50, turn on the doll
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 50) {
                myCharacter.ragdollEnabled = true;
                setTimeout(() => {
                    myCharacter.worldTransform.position = new Vector(0, 0, 130);
                    myCharacter.ragdollEnabled = false;
                }, 2000);
            }
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Generate a black hole effect to play circularly
            EffectService.playAtPosition("27693", new Vector(500, 0, 50), {loopCount: 0});
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the distance between the character and the center of the black hole is less than 300 and the character has not turned on the doll, move the character towards the center
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 300 && !myCharacter.ragdollEnabled) {
                let dir = new Vector(500, 0, 50).subtract(myCharacter.worldTransform.position).normalize();
                myCharacter.addMovement(new Vector(dir.x, dir.y, 0));
            }
            // If the distance between the character and the center of the black hole is less than 50, turn on the doll
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 50) {
                myCharacter.ragdollEnabled = true;
                setTimeout(() => {
                    myCharacter.worldTransform.position = new Vector(0, 0, 130);
                    myCharacter.ragdollEnabled = false;
                }, 2000);
            }
        }
    }
}

Returns ​

boolean

The character's doll effect, when interacting with other objects, allows the character to relax and swing like a doll when certain conditions occur, rather than maintaining a rigid body.

Precautions

Is the character currently in ragdoll state. True means use, and false means disable.

Parameters ​

value booleanTrue enables the doll effect, false disables it.

rotateRate ​

• get rotateRate(): number other

• set rotateRate(InRotateRate): void other

Obtain the maximum turning speed of the character
The maximum speed at which the character rotates per second. When set to a negative value, the turning speed is considered infinite and can be turned instantly.

Example usage: Create a script called "Instance_Character_SotateRate", place it in the object bar, open the script, enter the following code to save, run the game, you will set the character's turning speed to 0.5 times the original, and see the effect of slowing down the character's turning in the scene. The code is as follows:

ts
@Component
export default class Example_Character_RotateRate extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_Character_RotateRate extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

numberMaximum turning speed< The default value is 180 degrees per second.

Set the maximum turning speed for the character

Parameters ​

InRotateRatenumber

velocity ​

• get velocity(): Vector other

Get the current movement speed of the character

Precautions

The speed at which the character is currently moving

Usage example: create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save it, and run the game. If the character is moving, you will see the printed character moving speed in the console. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum acceleration is 0.1 times the original
            myCharacter.maxAcceleration = 0.1 * myCharacter.maxAcceleration;
            // The maximum turning speed is 0.5 times the original speed
            myCharacter.rotateRate = 0.5 * myCharacter.rotateRate;
            // The maximum walking speed is twice as fast as before
            myCharacter.maxWalkSpeed = 2 * myCharacter.maxWalkSpeed;
            // The maximum acceleration is 0.1 times the original
            myCharacter.brakingDecelerationWalking = 0.1 * myCharacter.brakingDecelerationWalking;
            myCharacter.groundFriction = 1;
            // Add a key method: press "1" on the keyboard to switch the source of character friction
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.groundFrictionEnabled = !myCharacter.groundFriction;
            });
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the character is moving, print the moving speed of the character
            if(myCharacter.isMoving) {
                Console. log ("Current character speed:"+myCharacter. velocity);
            }
        }
    }
}

Returns ​

VectorA three-dimensional vector of the magnitude and direction of the movement speed.

walkableFloorAngle ​

• get walkableFloorAngle(): number other

• set walkableFloorAngle(InWalkableFloorAngle): void other

Get the maximum angle that character can walk
When a character stands on a slope, the maximum angle of the slope. If the angle is exceeded, the character will not be able to stand on the slope, and the character will fall. The usage range is between 0-90.

Usage example: drag the used asset: "7667197386" into the priority loading column. Create a script called 'InstanceWalkableFloorAngle', place it in the object bar, open the script, enter the following code to save, run the game, and you will create 5 different slopes of cones in the scene: 1, 30, 45, 60, 89. Press "3" on the keyboard to increase the maximum walking angle of the character by 5. Press "4" on the keyboard, and the maximum walking angle of the character decreases by 5. You will see the effect of the maximum angle change that the character can walk. The code is as follows:

ts
@Component
export default class Example_WalkableFloorAngle extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the server side
         if(SystemUtil.isServer()) {
            // Create 5 cubes of different heights: 10, 20, 40, 80, 160
            let cubeHeight = [10, 20, 40, 80, 160];
            for (let i = 0;
i < cubeHeight.length;
i++) {
                GameObject.spawn("197386",{transform: new Transform(new Vector(250 * i, -500, 0), Rotation.zero, new Vector(2, 2, cubeHeight[i] / 100))});
            }
            // Create 5 cones with different slopes: 1, 30, 45, 60, 89
            let coneAngle = [1, 30, 45, 60, 89];
            for (let i = 0;
i < coneAngle.length;
i++) {
                console.log("1111");
                GameObject.spawn("7667",{transform: new Transform(new Vector(250 * i, 500, 0), Rotation.zero, new Vector(2, 2, Math.tan(coneAngle[i] * Math.PI / 180)))});
            }
         }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", and the maximum span height of the character increases by 10
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxStepHeight += 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "2" on the keyboard, and the maximum span height of the character will be reduced by 10
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.maxStepHeight -= 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "3" on the keyboard, and the maximum walking angle of the character increases by 5
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.walkableFloorAngle += 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
            // Add a key method: press "4" on the keyboard, and the maximum walking angle of the character decreases by 5
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.walkableFloorAngle -= 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
        }
    }
}
@Component
export default class Example_WalkableFloorAngle extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the server side
         if(SystemUtil.isServer()) {
            // Create 5 cubes of different heights: 10, 20, 40, 80, 160
            let cubeHeight = [10, 20, 40, 80, 160];
            for (let i = 0;
i < cubeHeight.length;
i++) {
                GameObject.spawn("197386",{transform: new Transform(new Vector(250 * i, -500, 0), Rotation.zero, new Vector(2, 2, cubeHeight[i] / 100))});
            }
            // Create 5 cones with different slopes: 1, 30, 45, 60, 89
            let coneAngle = [1, 30, 45, 60, 89];
            for (let i = 0;
i < coneAngle.length;
i++) {
                console.log("1111");
                GameObject.spawn("7667",{transform: new Transform(new Vector(250 * i, 500, 0), Rotation.zero, new Vector(2, 2, Math.tan(coneAngle[i] * Math.PI / 180)))});
            }
         }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press the keyboard "1", and the maximum span height of the character increases by 10
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.maxStepHeight += 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "2" on the keyboard, and the maximum span height of the character will be reduced by 10
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.maxStepHeight -= 10;
                Console.log ("Maximum height that a character can cross:"+myCharacter. maxStepHeight);
            });
            // Add a key method: press "3" on the keyboard, and the maximum walking angle of the character increases by 5
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.walkableFloorAngle += 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
            // Add a key method: press "4" on the keyboard, and the maximum walking angle of the character decreases by 5
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.walkableFloorAngle -= 5;
                Console.log ("maximum walkable angle:"+myCharacter. walkableFloorAngle);
            });
        }
    }
}

Returns ​

numberMaximum angle< Br>The default value is 45 (angle value)

Set the maximum angle at which the character can walk

Parameters ​

InWalkableFloorAngle numberThe maximum angle that can be walked< br> range: [0,)

nameDisplayDistance ​

• Static get nameDisplayDistance(): number other

• Static set nameDisplayDistance(range): void other

Get the visible distance of the overhead display names of all characters in the current client.

Precautions

Display Name Visible Distance

Returns ​

numberDisplay name visible distance
The default value is 2000.

Set the visible distance of the display name above the head of all character in the current client. It takes effect when the display name above the head of character is visible. Not visible when the distance is 0.

Precautions

Display Name Visible Distance

Parameters ​

range numberDisplay Name Visible Distance
Range: (0,+∞)

nameVisible ​

• Static get nameVisible(): boolean other

• Static set nameVisible(isVisible): void other

Retrieve whether the overhead display names of all characters in the current client are visible.

Returns ​

booleanWhen true, the name displayed on the top of the character's head is visible, and when false, the name displayed on the top of the character's head is not visible< Default is visible.

Set whether the top display names of all character on the current client are visible

Parameters ​

isVisible booleanWhen it is true, the display name above the character is visible; when it is false, the display name above the character is invisible.

Methods ​


addImpulse ​

• addImpulse(vector, ignoreMass?): void other

When impulse is added, the force effect will be different with the same impulse value when the doll is in normal state\

Parameters ​

vector VectorUsage: impulse of the application
ignoreMass? booleanUsage: Whether to ignore the influence of quality on impulse default: false

Usage example: drag the used asset: "12218012218213263175354" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate a generate cannon model in the scene. Add generate a Trigger to the cannon and add it to the delegate. When the character enters the range, send the [Launch] event to the server. If the character enters the Trigger, you can see the effect of adding a impulse to the character and being fired by the cannon. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate cannon model
            let cannon_base = GameObject.spawn("122180",{transform: new Transform(new Vector(750, 0, 0), new Rotation(0, 0, -90), Vector.one.multiply(2))});
            let cannon_tube  = GameObject.spawn("122182",{transform: new Transform(new Vector(750, 0, 250), new Rotation(0, 30, 90), Vector.one.multiply(2))});
            // Add a [Launch] event listener on the server to add impulse to the character
            mw.Event.addClientListener("Launch", (player) => {
                player.character.addImpulse(new Vector(0, 1, 1).multiply(1000), true);
            });
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Trigger and add it to the delegate. When the character enters the range, send the [Send] event to the server
            let cannon_trigger  = GameObject.spawn("Trigger",{transform: new Transform(new Vector(750, 0, 0), new Rotation(0, 30, 90), Vector.one.multiply(4))}) as Trigger;
            cannon_trigger.onEnter.add((character: Character) => {
                character.worldTransform.position = new Vector(750, 275, 330);
                // Dispatch the [Launch] event to the server
                mw.Event.dispatchToServer("Launch");
                // Play sound effects and special effects.
                EffectService.playAtPosition("132631", new Vector(750, 275, 330))
                SoundService.playSound("75354");
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate cannon model
            let cannon_base = GameObject.spawn("122180",{transform: new Transform(new Vector(750, 0, 0), new Rotation(0, 0, -90), Vector.one.multiply(2))});
            let cannon_tube  = GameObject.spawn("122182",{transform: new Transform(new Vector(750, 0, 250), new Rotation(0, 30, 90), Vector.one.multiply(2))});
            // Add a [Launch] event listener on the server to add impulse to the character
            mw.Event.addClientListener("Launch", (player) => {
                player.character.addImpulse(new Vector(0, 1, 1).multiply(1000), true);
            });
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Trigger and add it to the delegate. When the character enters the range, send the [Send] event to the server
            let cannon_trigger  = GameObject.spawn("Trigger",{transform: new Transform(new Vector(750, 0, 0), new Rotation(0, 30, 90), Vector.one.multiply(4))}) as Trigger;
            cannon_trigger.onEnter.add((character: Character) => {
                character.worldTransform.position = new Vector(750, 275, 330);
                // Dispatch the [Launch] event to the server
                mw.Event.dispatchToServer("Launch");
                // Play sound effects and special effects.
                EffectService.playAtPosition("132631", new Vector(750, 275, 330))
                SoundService.playSound("75354");
            });
        }
    }
}

addMovement ​

• addMovement(direction): void other

Add motion input along the given direction vector\

Parameters ​

direction VectorUsage: Input direction

The effect is affected by the movementDirection property. If there are user inputs at the same time, the effect is overlay rather than overlay.

Usage example: drag the used asset: "27693" into the priority loading column. Create a script named "Example_Character_AddMovement", place it in the object bar, open the script, enter the following code to save, run the game, and you will generate a circular black hole effect in the scene. If the distance between the character and the center of the black hole is less than 300 and the character does not open the doll, move the character toward the center. If the distance between the character and the center of the black hole is less than 50, turn on the doll. You can see the different effect codes of the character switch doll are as follows:

ts
@Component
export default class Example_Character_AddMovement extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Generate a black hole effect to play circularly
            EffectService.playAtPosition("27693", new Vector(500, 0, 50), {loopCount: 0});
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the distance between the character and the center of the black hole is less than 300 and the character has not turned on the doll, move the character towards the center
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 300 && !myCharacter.ragdollEnabled) {
                let dir = new Vector(500, 0, 50).subtract(myCharacter.worldTransform.position).normalize();
                myCharacter.addMovement(new Vector(dir.x, dir.y, 0));
            }
            // If the distance between the character and the center of the black hole is less than 50, turn on the doll
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 50) {
                myCharacter.ragdollEnabled = true;
                setTimeout(() => {
                    myCharacter.worldTransform.position = new Vector(0, 0, 130);
                    myCharacter.ragdollEnabled = false;
                }, 2000);
            }
        }
    }
}
@Component
export default class Example_Character_AddMovement extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            this.useUpdate = true;
            // Generate a black hole effect to play circularly
            EffectService.playAtPosition("27693", new Vector(500, 0, 50), {loopCount: 0});
        }
    }
    // The periodic function is executed on a frame by frame basis. To execute this function, the value of this.useUpdate needs to be set to true, where dt is the delay (in seconds) between the current frame and the previous frame
    protected onUpdate(dt: number): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // If the distance between the character and the center of the black hole is less than 300 and the character has not turned on the doll, move the character towards the center
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 300 && !myCharacter.ragdollEnabled) {
                let dir = new Vector(500, 0, 50).subtract(myCharacter.worldTransform.position).normalize();
                myCharacter.addMovement(new Vector(dir.x, dir.y, 0));
            }
            // If the distance between the character and the center of the black hole is less than 50, turn on the doll
            if(myCharacter.worldTransform.position.subtract(new Vector(500, 0, 50)).length < 50) {
                myCharacter.ragdollEnabled = true;
                setTimeout(() => {
                    myCharacter.worldTransform.position = new Vector(0, 0, 130);
                    myCharacter.ragdollEnabled = false;
                }, 2000);
            }
        }
    }
}

attachToSlot ​

• attachToSlot(gameObject, slotName): void other

Attach an object to the designated slot of the character character\

Parameters ​

gameObject GameObjectAttached object
slotName NonHumanoidSlotType HumanoidSlotTypeSlot name, attached to the specified slot name

Usage example: Drag the resource "277042905211814912295326168" into the priority loading bar. Create a script named 'Instance_Character_TattachoSlot', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', and add/remove the character's overhead halo. Press keyboard "2" to equip the character slot with a model. Press keyboard "3" to remove all objects mounted on the slots of the character's left hand, right hand, and left back. Press "4" on the keyboard to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character_AttachToSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}
@Component
export default class Example_Character_AttachToSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}

cancelHeadFollow ​

• cancelHeadFollow(): void other

Cancel head tracking


changeState ​

• changeState(stateType): void other

Change the status of character

Parameters ​

stateType CharacterStateTypeNew state Example usage: Press 0-9, Z, X, C, V to view the current character status ```

clearDescription ​

• clearDescription(appearance?, slotAndDecoration?): void other

Clear character appearance data\

Parameters ​

appearance? booleanUsage: whether to clear appearance data default: true
slotAndDecoration? booleanUsage: whether to empty the slot and item data default: true

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

detachAllFromSlot ​

• detachAllFromSlot(param?): void other

Separate all objects attached to the character slot\

Parameters ​

param? Object(Optional parameter) Slot data, the following two are the data structures for params: slotName: mw.HumanoidSlotType; isDestroy: boolean
default:null
param.isDestroy? booleanDo you want to destroy these separated slots
param.slotName? HumanoidSlotTypeUsage: Separate slot name

Usage example: drag the used asset: "277042905211814912295326168" into the priority loading column. Create a script named "Example_Character_DetachAllFromSlot", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1" to add/remove the overhead aura of the character. Press "2" on the keyboard to equipment the model for the character slot. Press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back. Press the keyboard "4" to generate a special effect at the top vertex 0 position and the top UI position of the character's head. The code is as follows:

ts
@Component
export default class Example_Character_DetachAllFromSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}
@Component
export default class Example_Character_DetachAllFromSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}

detachFromSlot ​

• detachFromSlot(gameObject): void other

Separate the object from the slot

Parameters ​

gameObject GameObjectObject GameObject

Usage example: Drag the resource "277042905211814912295326168" into the priority loading bar. Create a script named 'Instance_Character_SetachFromSlot', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', and add/remove the character's overhead halo. Press keyboard "2" to equip the character slot with a model. Press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back. Press "4" on the keyboard to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character_DetachFromSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}
@Component
export default class Example_Character_DetachFromSlot extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}

getCenterVertexByMorphName ​

• getCenterVertexByMorphName(morphName): Vector other

Real time acquisition of center vertex position through the head model MorphName

Parameters ​

morphName stringMorphName

Returns ​

Vector@networkStatus Usage: Dual ended

getCurrentState ​

• getCurrentState(): CharacterStateType other

Get the current status of the character

Returns ​

CharacterStateTypeCurrent role status

Usage example: Press E to view the current status and print

ts
@Component
export default class NewScript1 extends Script {
    private character: Character;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        Player.asyncGetLocalPlayer().then((player) => {
            this.character = player.character;
            this.character.onStateChanged.add((pre, curr)=>{
                console.log(`pre: ${pre} curr: ${curr}`);
            })
        });
      InputUtil.onKeyDown(Keys.Zero, ()=>{
            this.character.changeState(CharacterStateType.None);
        })
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.character.changeState(CharacterStateType.Running);
        })
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.character.changeState(CharacterStateType.Flying);
        })
        InputUtil.onKeyDown(Keys.Three, ()=>{
            this.character.changeState(CharacterStateType.Swimming);
        })
        InputUtil.onKeyDown(Keys.Four, ()=>{
            this.character.changeState(CharacterStateType.Jumping);
        })
        InputUtil.onKeyDown(Keys.Five, ()=>{
            this.character.changeState(CharacterStateType.Freefall);
        })
        InputUtil.onKeyDown(Keys.Six, ()=>{
            this.character.changeState(CharacterStateType.Ragdoll);
        })
        InputUtil.onKeyDown(Keys.Seven, ()=>{
            this.character.changeState(CharacterStateType.GettingUp);
        })
        InputUtil.onKeyDown(Keys.Eight, ()=>{
            this.character.changeState(CharacterStateType.Climbing);
        })
        InputUtil.onKeyDown(Keys.Nine, ()=>{
            this.character.changeState(CharacterStateType.Crouching);
        })
        InputUtil.onKeyDown(Keys.Z, ()=>{
            this.character.changeState(CharacterStateType.Pushed);
        })
        InputUtil.onKeyDown(Keys.X, ()=>{
            this.character.changeState(CharacterStateType.Landed);
        })
        InputUtil.onKeyDown(Keys.C, ()=>{
            this.character.changeState(CharacterStateType.Hit);
        })
        InputUtil.onKeyDown(Keys.V, ()=>{
            this.character.changeState(CharacterStateType.Dead);
        })
        InputUtil.onKeyDown(Keys.E, ()=>{
            console.log("currentState=="+this.character.getCurrentState());
        })
    }
}
@Component
export default class NewScript1 extends Script {
    private character: Character;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        Player.asyncGetLocalPlayer().then((player) => {
            this.character = player.character;
            this.character.onStateChanged.add((pre, curr)=>{
                console.log(`pre: ${pre} curr: ${curr}`);
            })
        });
      InputUtil.onKeyDown(Keys.Zero, ()=>{
            this.character.changeState(CharacterStateType.None);
        })
        InputUtil.onKeyDown(Keys.One, ()=>{
            this.character.changeState(CharacterStateType.Running);
        })
        InputUtil.onKeyDown(Keys.Two, ()=>{
            this.character.changeState(CharacterStateType.Flying);
        })
        InputUtil.onKeyDown(Keys.Three, ()=>{
            this.character.changeState(CharacterStateType.Swimming);
        })
        InputUtil.onKeyDown(Keys.Four, ()=>{
            this.character.changeState(CharacterStateType.Jumping);
        })
        InputUtil.onKeyDown(Keys.Five, ()=>{
            this.character.changeState(CharacterStateType.Freefall);
        })
        InputUtil.onKeyDown(Keys.Six, ()=>{
            this.character.changeState(CharacterStateType.Ragdoll);
        })
        InputUtil.onKeyDown(Keys.Seven, ()=>{
            this.character.changeState(CharacterStateType.GettingUp);
        })
        InputUtil.onKeyDown(Keys.Eight, ()=>{
            this.character.changeState(CharacterStateType.Climbing);
        })
        InputUtil.onKeyDown(Keys.Nine, ()=>{
            this.character.changeState(CharacterStateType.Crouching);
        })
        InputUtil.onKeyDown(Keys.Z, ()=>{
            this.character.changeState(CharacterStateType.Pushed);
        })
        InputUtil.onKeyDown(Keys.X, ()=>{
            this.character.changeState(CharacterStateType.Landed);
        })
        InputUtil.onKeyDown(Keys.C, ()=>{
            this.character.changeState(CharacterStateType.Hit);
        })
        InputUtil.onKeyDown(Keys.V, ()=>{
            this.character.changeState(CharacterStateType.Dead);
        })
        InputUtil.onKeyDown(Keys.E, ()=>{
            console.log("currentState=="+this.character.getCurrentState());
        })
    }
}

getDescription ​

• getDescription(): CharacterDescription other

Get character appearance data\

Returns ​

CharacterDescriptionCopy of character appearance data
This interface retrieves a copy of the current appearance data of the character

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

getSlotWorldPosition ​

• getSlotWorldPosition(slotName): Vector other

Obtain the world coordinates of the character slot\

Parameters ​

slotName HumanoidSlotTypeUsage: Slot name

Returns ​

VectorCoordinate position
Affected by the offset of the slot in the character appearance, it is only effective for advanced humanoid character.

Usage example: drag the used asset: "277042905211814912295326168" into the priority loading column. Create a script named 'Instance_Character_GetLotWorldPosition', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', and add/remove the character's overhead halo. Press keyboard "2" to equip the character slot with a model. Press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back. Press "4" on the keyboard to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character_GetSlotWorldPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}
@Component
export default class Example_Character_GetSlotWorldPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            let halo = null;
            // Add a key method: press the keyboard "1" to add/remove the character's overhead aura
            InputUtil.onKeyDown(Keys.One, () => {
                if(halo) {
                    myCharacter.detachFromSlot(halo);
                    setTimeout(() => {
                        halo.destroy();
                        halo = null;
                    }, 1000);
                } else {
                    // Generate a halo above the character's head and attach it to the slot above the head
                    halo = GameObject.spawn("27704") as Effect;
                    myCharacter.attachToSlot(halo, HumanoidSlotType.Rings);
                    halo.play();
                }
            });
            // Generate three equipment
            let sword = GameObject.spawn("29052",{transform: new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one)});
            let shield = GameObject.spawn("118149",{transform: new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one)});
            let spike = GameObject.spawn("122953",{transform: new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one)});
            // Add a button method: Press keyboard "2" to add equipment to the character slot
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.attachToSlot(sword, HumanoidSlotType.RightHand);
                myCharacter.attachToSlot(shield, HumanoidSlotType.LeftHand);
                myCharacter.attachToSlot(spike, HumanoidSlotType.LeftBack);
            });
            // Add a key method: press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.detachAllFromSlot();
                sword.worldTransform = new Transform(new Vector(300, -100, 100), Rotation.zero, Vector.one);
                shield.worldTransform = new Transform(new Vector(300, 0, 100), Rotation.zero, Vector.one);
                spike.worldTransform = new Transform(new Vector(300, 100, 100), Rotation.zero, Vector.one);
            });
            // Add a key method: press the keyboard "4" to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI
            InputUtil.onKeyDown(Keys.Four, () => {
                let pos = myCharacter.getVertexPosition(0);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
                pos = myCharacter.getSlotWorldPosition(HumanoidSlotType.Rings);
                if(pos) {
                    let zzz = GameObject.spawn("26168") as Effect;
                    zzz.worldTransform.position = pos;
                    zzz.play(() => {
                        zzz.destroy();
                    });
                }
            });
        }
    }
}

getVertexArrayByMorphName ​

• getVertexArrayByMorphName(morphName): Vector[] other

Real time acquisition of all vertex positions through the head model MorphName

Parameters ​

morphName stringMorphName range: Morph name

Returns ​

Vector[]Vertex Position Array

Usage example: Drag the resource "277042905211814912295326168" into the priority loading bar. Create a script named 'Instance_Character_GetVertexPosition', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', and add/remove the character's overhead halo. Press "2" on the keyboard to equipment the model for the character slot. Press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back. Press "4" on the keyboard to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character_GetVertexPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    *    private character: Character;
   private obj: Model;
   protected onStart(): void {
       this.useUpdate = true;
       Player.asyncGetLocalPlayer().then((player)=>{
           this.character = player.character;
       })
       GameObject.asyncSpawn("84121").then((obj)=>{
           this.obj = obj as Model;
           this.obj.worldTransform.scale = new Vector(0.1,0.1,0.1);
           this.obj.setCollision(CollisionStatus.Off);
       })
   }
   protected onUpdate(dt: number): void {
       if (this.character && this.obj) {
           this.obj.worldTransform.position = this.character.getVertexArrayByMorphName("EarOverallScale")[0];
       }
   }
}
@Component
export default class Example_Character_GetVertexPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    *    private character: Character;
   private obj: Model;
   protected onStart(): void {
       this.useUpdate = true;
       Player.asyncGetLocalPlayer().then((player)=>{
           this.character = player.character;
       })
       GameObject.asyncSpawn("84121").then((obj)=>{
           this.obj = obj as Model;
           this.obj.worldTransform.scale = new Vector(0.1,0.1,0.1);
           this.obj.setCollision(CollisionStatus.Off);
       })
   }
   protected onUpdate(dt: number): void {
       if (this.character && this.obj) {
           this.obj.worldTransform.position = this.character.getVertexArrayByMorphName("EarOverallScale")[0];
       }
   }
}

getVertexPosition ​

• getVertexPosition(index): Vector other

Real-time acquisition of vertex position through vertex index of head model\

Parameters ​

index numberModel vertex index
range: determined based on the data of the skeleton mesh object vertices. Type: integer

Returns ​

VectorVertex position
At present, the vertex index can only be viewed from internal engineering

Usage example: Drag the resource "277042905211814912295326168" into the priority loading bar. Create a script named 'Instance_Character_GetVertexPosition', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', and add/remove the character's overhead halo. Press "2" on the keyboard to equipment the model for the character slot. Press "3" on the keyboard to remove all objects attached to the slot of the character's left hand, right hand and left back. Press "4" on the keyboard to generate a effect at the position of the character's top vertex 0 and the position of the overhead UI. The code is as follows:

ts
@Component
export default class Example_Character_GetVertexPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    *    private character: Character;
   private obj: Model;
   protected onStart(): void {
       this.useUpdate = true;
       Player.asyncGetLocalPlayer().then((player)=>{
           this.character = player.character;
       })
       GameObject.asyncSpawn("84121").then((obj)=>{
           this.obj = obj as Model;
           this.obj.worldTransform.scale = new Vector(0.1,0.1,0.1);
           this.obj.setCollision(CollisionStatus.Off);
       })
   }
   protected onUpdate(dt: number): void {
       if (this.character && this.obj) {
           this.obj.worldTransform.position = this.character.getVertexPosition(0);
       }
   }
}
@Component
export default class Example_Character_GetVertexPosition extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    *    private character: Character;
   private obj: Model;
   protected onStart(): void {
       this.useUpdate = true;
       Player.asyncGetLocalPlayer().then((player)=>{
           this.character = player.character;
       })
       GameObject.asyncSpawn("84121").then((obj)=>{
           this.obj = obj as Model;
           this.obj.worldTransform.scale = new Vector(0.1,0.1,0.1);
           this.obj.setCollision(CollisionStatus.Off);
       })
   }
   protected onUpdate(dt: number): void {
       if (this.character && this.obj) {
           this.obj.worldTransform.position = this.character.getVertexPosition(0);
       }
   }
}

headFollow ​

• headFollow(target): void other

Head tracking

Parameters ​

target null GameObject VectorTracking point or object

jump ​

• jump(): void other

Make the character trigger a jump behavior

Example usage: Create a script called "Instance_Character_Jump", place it in the object bar, open the script, enter the following code to save, run the game, set the character's maximum jump height to 300, and the highest triple jump. Press the keyboard "1", and the character jumps. Press the keyboard "2" to enable/disable the jumping ability. You will see the effect of disable the jumping ability of the character in the scene. The code is as follows:

ts
@Component
export default class Example_Character_Jump extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a button method: Press keyboard "1" to jump the character.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}
@Component
export default class Example_Character_Jump extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // The maximum jumping height is 300
            myCharacter.maxJumpHeight = 300;
            // Highest triple jump
            myCharacter.jumpMaxCount = 3;
            // Add a button method: Press keyboard "1" to jump the character.
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.jump();
                Console. log ("Is the current character jumping"+myCharacter. isJumping);
            });
            // Add a key method: Press keyboard "2" to enable/disable jumping ability.
            InputUtil.onKeyDown(Keys.Two, () => {
                myCharacter.jumpEnabled = !myCharacter.jumpEnabled;
                Console. log ("current character's jumping ability"+myCharacter. dumpEnabled);
            });
        }
    }
}

loadAnimation ​

• loadAnimation(assetId): Animation other

Load an animation resource for the character\

Parameters ​

assetId stringUsage: animation Asset ID (animation in the left column of the editor, right click a animation asset to copy Asset ID)
range: string length depends on the specific Asset ID

Returns ​

AnimationAnimation objects
loadAnimation The given animation will be loaded onto the character and a playable Animation will be returned.

Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, load dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion. When the animation is played, a upgrade effect will appear. Press the keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a dance animation for the character
            let danceAnimation = myCharacter.loadAnimation("14700");
            // Property of animation
            Console.log ("animation duration"+danceAnimation. length);
            // Loop playback 10 times
            danceAnimation.loop = 10;
            // 2x playback speed
            danceAnimation.speed = 2;
            // Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
            danceAnimation.onFinish.add(() => {
                EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
            });
            // Add a key method: press the keyboard "1" to start playing
            InputUtil.onKeyDown(Keys.One, () => {
                danceAnimation.play();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "2" on the keyboard to pause playback
            InputUtil.onKeyDown(Keys.Two, () => {
                danceAnimation.pause();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "3" on the keyboard to continue playing
            InputUtil.onKeyDown(Keys.Three, () => {
                danceAnimation.resume();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "4" on the keyboard to stop playing
            InputUtil.onKeyDown(Keys.Four, () => {
                danceAnimation.stop();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a dance animation for the character
            let danceAnimation = myCharacter.loadAnimation("14700");
            // Property of animation
            Console.log ("animation duration"+danceAnimation. length);
            // Loop playback 10 times
            danceAnimation.loop = 10;
            // 2x playback speed
            danceAnimation.speed = 2;
            // Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
            danceAnimation.onFinish.add(() => {
                EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
            });
            // Add a key method: press the keyboard "1" to start playing
            InputUtil.onKeyDown(Keys.One, () => {
                danceAnimation.play();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "2" on the keyboard to pause playback
            InputUtil.onKeyDown(Keys.Two, () => {
                danceAnimation.pause();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "3" on the keyboard to continue playing
            InputUtil.onKeyDown(Keys.Three, () => {
                danceAnimation.resume();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
            // Add a key method: press "4" on the keyboard to stop playing
            InputUtil.onKeyDown(Keys.Four, () => {
                danceAnimation.stop();
                Console.log ("animation playing"+danceAnimation. isPlaying);
            });
        }
    }
}

loadStance ​

• loadStance(assetId): Stance other

Load a base stance for the character\

Parameters ​

assetId stringBasic posture resource ID
range: The string length depends on the specific resource ID

Returns ​

StanceBasic posture object
LoadStance will load the given base pose onto the character and return a playable base pose stance type.

Usage example: drag the used asset: "23442316081" into the priority loading column. Create a script named 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1', switch between playing 2D male basic pose and 2D female basic pose. Press keyboard "2" to stop playing the basic posture. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a anime male basic stance to the character
            let animeManStance = myCharacter.loadStance("234423");
            console.log("animeManStance assetId " + animeManStance.assetId);
            // Load a anime female basic stance for the character (default), and turn off aim offset
            let animeWomanStance = myCharacter.loadStance("216081");
            animeWomanStance.aimOffsetEnabled = false;
            console.log("animeWomanStance assetId " + animeWomanStance.assetId);
            // Add a button method: Press keyboard "1" to switch between playing 2D male basic poses and 2D female basic poses
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentStance == animeWomanStance) {
                    animeManStance.play();
                    // Enable aim offset
                    animeManStance.aimOffsetEnabled = true;
                } else {
                    animeWomanStance.play();
                    // Close aim offset
                    animeWomanStance.aimOffsetEnabled = false;
                }
            });
            // Add a button method: Press keyboard "2" to stop playing the basic posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentStance) {
                    myCharacter.currentStance.stop();
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load a anime male basic stance to the character
            let animeManStance = myCharacter.loadStance("234423");
            console.log("animeManStance assetId " + animeManStance.assetId);
            // Load a anime female basic stance for the character (default), and turn off aim offset
            let animeWomanStance = myCharacter.loadStance("216081");
            animeWomanStance.aimOffsetEnabled = false;
            console.log("animeWomanStance assetId " + animeWomanStance.assetId);
            // Add a button method: Press keyboard "1" to switch between playing 2D male basic poses and 2D female basic poses
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentStance == animeWomanStance) {
                    animeManStance.play();
                    // Enable aim offset
                    animeManStance.aimOffsetEnabled = true;
                } else {
                    animeWomanStance.play();
                    // Close aim offset
                    animeWomanStance.aimOffsetEnabled = false;
                }
            });
            // Add a button method: Press keyboard "2" to stop playing the basic posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentStance) {
                    myCharacter.currentStance.stop();
                }
            });
        }
    }
}

loadSubStance ​

• loadSubStance(assetId): SubStance other

Load a secondary stance for the character

Parameters ​

assetId stringAttitude resource ID or animation resource ID
range: The length of the string depends on the specific resource ID

Returns ​

SubStanceSecondary attitude object

Usage example: drag the used asset: "9426114520" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save it, run the game, and load a aim stance with only upper body and a kicking stance with only lower body on the Player's character. Press the keyboard "1" to switch between playing aiming posture and kicking posture. Press "2" on the keyboard to stop playing stance. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load only upper aim stance for character
            let aimStance = myCharacter.loadSubStance("94261");
            aimStance.blendMode = StanceBlendMode.BlendUpper;
            console.log("aimStance assetId " + aimStance.assetId);
            // Load the character with only lower body kicking posture
            let kickStance = myCharacter.loadSubStance("14520");
            kickStance.blendMode = StanceBlendMode.BlendLower;
            console.log("kickStance assetId " + kickStance.assetId);
            // Add a key method: press the keyboard "1" to switch between aim stance and kicking stance
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentSubStance == aimStance) {
                    kickStance.play();
                } else {
                    aimStance.play();
                }
            });
            // Add a button method: Press keyboard "2" to stop playing posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentSubStance) {
                    myCharacter.currentSubStance.stop();
                }
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // Load only upper aim stance for character
            let aimStance = myCharacter.loadSubStance("94261");
            aimStance.blendMode = StanceBlendMode.BlendUpper;
            console.log("aimStance assetId " + aimStance.assetId);
            // Load the character with only lower body kicking posture
            let kickStance = myCharacter.loadSubStance("14520");
            kickStance.blendMode = StanceBlendMode.BlendLower;
            console.log("kickStance assetId " + kickStance.assetId);
            // Add a key method: press the keyboard "1" to switch between aim stance and kicking stance
            InputUtil.onKeyDown(Keys.One, () => {
                if(myCharacter.currentSubStance == aimStance) {
                    kickStance.play();
                } else {
                    aimStance.play();
                }
            });
            // Add a button method: Press keyboard "2" to stop playing posture
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.currentSubStance) {
                    myCharacter.currentSubStance.stop();
                }
            });
        }
    }
}

setCollisionShapeAndExtent ​

• setCollisionShapeAndExtent(shapeType, collisionExtent): void other

Set collision bodies of different shapes and sizes for character

Parameters ​

shapeType CustomShapeTypeShape of collision body (capsule, spherical, box)
collisionExtent VectorThe size of the shape of the collision body

Usage example: drag the used asset: "36851" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, generate an arch with collision and a single ended NPC, and show the character collision effect. Press keyboard "1" to turn on/off collisions between NPCs and other characters. Press keyboard "2" to turn on/off whether NPCs can be stood up. Press "3" on the keyboard to modify the shape and size of character collision and print the result.

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            // Generate single ended NPC to show character collision
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Generate Arch Arch with collision
            let arch = GameObject.spawn("36851",{transform: new Transform(new Vector(300, 210, 0), new Rotation(0, 0, 90), new Vector(2, 1, 2))}) as Model;
            arch.setCollision(CollisionStatus.On);
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Set character collision property and jump property
            myCharacter.capsuleCorrectionEnabled = true;
            myCharacter.maxJumpHeight = 250;
            // Generate single ended NPC to show character collision
            let NPC = Player.spawnDefaultCharacter();
            NPC.worldTransform.position = new Vector(0, 100, 100);
            // Add a key method: press "1" on the keyboard to turn on/off the collision between NPC and other character
            InputUtil.onKeyDown(Keys.One, () => {
                NPC.collisionWithOtherCharacterEnabled = !NPC.collisionWithOtherCharacterEnabled;
                Console. log ("collision between NPC and character"+NPC. collisionWithOtherCharacterEnabled);
            });
            // Add a button method: Press keyboard "2" to turn on/off whether the character can be stood up
            InputUtil.onKeyDown(Keys.Two, () => {
                NPC.canStandOn = !NPC.canStandOn;
                Console. log ("NPC character can be standing"+NPC. canStandOn);
            });
            // Add a button method: Press keyboard "3" to modify character collision and print the result
            InputUtil.onKeyDown(Keys.Three, () => {
                // The collision range collisionExtent internal values are all half values, and the radius is half height and half length
                myCharacter.setCollisionShapeAndExtent(CustomShapeType.Box, new Vector(50, 50, 200));
                Console. log ("Current character collision"+myCharacter. collisionShape+""+myCharacter. collisionExtent);
            });
        }
    }
}

setDescription ​

• setDescription(data): void other

Set character appearance data\

Parameters ​

data string string[] CharacterDescriptionUsage: Appearance data

setStyle To set the appearance of a character, you can import the CharacterDescription object/array of character appearance file/guid of attachment data file.

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script called 'Instance_Character', place it in the object bar, open the script, enter the following code to save, run the game, and you will see in the scene that the player controls the appearance of the character, prepares the player's appearance, and plays the idle hand effect. [Character Appearance Description Completed] Entrust the addition of a function to play the special effect of changing costumes and save the initial default appearance data of the character. [character appearance Description Change] delegate to add a function to print the specific subitems and indexes of the current character appearance description change on the console. Press the keyboard "1" to reset to the default character appearance. Press "2" on the keyboard to modify the character appearance. Press "3" on the keyboard to sync the character appearance. Press keyboard "4" to clear the appearance of the character. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}

setStateEnabled ​

• setStateEnabled(characterStateType, enabled): void other

Set role status switch

Parameters ​

characterStateType CharacterStateTypeCharacter Status
enabled booleanWhether the character status is enable Usage example: press R to disable flight status, and then press 2 to switch flight ```

swimUpDown ​

• swimUpDown(speed): void other

Make character float and dive in the water

Parameters ​

speed numberUsage: Speed, greater than 0 means floating up, less than 0 means diving
Range: No restrictions. Type: Floating point number

Usage example: Drag the resource "5301120307" into the priority loading bar. Create a script called 'Instance_Character_SwimUp', place it in the object bar, open the script, enter the following code to save, run the game, and you will generate an arched container in the scene and adapt it to the swimming area. Press the keyboard "1", and the character switches swimming. Press "4" on the keyboard, and the character will modify the maximum swimming speed for jet acceleration. You can see the effect of the maximum swimming speed change of the character. The code is as follows:

ts
@Component
export default class Example_Character_SwimUp extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUpDown(100);
            });
            // Add a key method: press and hold the keyboard "3", and the character will dive
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimUpDown(-100);
            });
        }
    }
}
@Component
export default class Example_Character_SwimUp extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Generate arch Container and adapt to swimming area
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(20, 20, 10))});
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            let flag = true;
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Add a key method: press "1" on the keyboard to switch between swimming/walking for character
            InputUtil.onKeyDown(Keys.One, () => {
                if(flag) {
                    myCharacter.switchToWalking();
                } else {
                    myCharacter.switchToSwimming();
                }
                flag = !flag;
            });
            // Add a key method: press and hold the keyboard "2", and the character will float up
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimUpDown(100);
            });
            // Add a key method: press and hold the keyboard "3", and the character will dive
            InputUtil.onKeyPress(Keys.Three, () => {
                myCharacter.swimUpDown(-100);
            });
        }
    }
}

syncDescription ​

• syncDescription(appearance?, slotAndDecoration?): void other

Synchronize character appearance data\

Parameters ​

appearance? booleanUsage: Role synchronization default: true
slotAndDecoration? booleanUsage: slot and decoration sync default: true

Usage example: drag the used asset: "145213539116124575674577316391058694587006038458696136183" into the priority loading column. Create a script named "Example_Character", place it in the object bar, open the script, enter the following code to save, run the game, and you will see the effect of Player control the appearance of the character Player in the scene. Add a function to delegate [character appearance Description Complete] to play the effect after the costume change is completed, and save the initial default appearance data of the character. Add a function to the delegate of character appearance Description Change to print the specific subitems and indexes of the current character appearance Description Change on the console. Press keyboard "1" to reset to the default character appearance. Press keyboard "2" to modify the appearance of the character. Press keyboard "3" to synchronize the appearance of the character. Press the keyboard "4" to clear the character appearance. The code is as follows:

ts
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}
@Component
export default class Example_Character extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client Player
            let myPlayer = Player.localPlayer;
            // Get Player control character
            let myCharacter = myPlayer.character;
            // If the player's appearance is ready, wave your hand; otherwise, wave your hand
            if(myCharacter.isDescriptionReady) {
                let animation = myCharacter.loadAnimation("35391");
                animation.play();
            } else {
                let animation = myCharacter.loadAnimation("14521");
                animation.play();
            }
            let defaultStyle = null;
            // Add a function to the delegate of character appearance Description Complete
            myCharacter.onDescriptionComplete.add(() => {
                // Play the effect after changing clothes
                EffectService.playOnGameObject("161245", myCharacter, {slotType: HumanoidSlotType.Root});
                // Get the default appearance style of the character
                if(defaultStyle == null) {
                    defaultStyle = myCharacter.getDescription();
                }
            });
            // Delegate the addition of a function for 'Change in Character Appearance Description'
            myCharacter.onDescriptionChange.add((operationCode: number, index: number, value: unknown) => {
                console.log("Appearance Changed");
                console.log("OperationCode " + operationCode + " Index " + index);
            });
            // Add a button method: Press keyboard "1" to reset to default character appearance
            InputUtil.onKeyDown(Keys.One, () => {
                myCharacter.setDescription(defaultStyle);
            });
            // Add a key method: press "2" on the keyboard to modify the character appearance
            InputUtil.onKeyDown(Keys.Two, () => {
                if(myCharacter.characterType == CharacterType.HumanoidV2) {
                    // Change character style head: Head size is 1.5 times
                    myCharacter.description.advance.headFeatures.head.headOverallScale = 1.5;
                    // Change character style and body shape: Height is 1.2 times
                    myCharacter.description.advance.bodyFeatures.body.height = 1.2;
                    // Change character style makeup: blush to 75674
                    myCharacter.description.advance.makeup.blush.blushStyle = "75674";
                    // Modify the character style hair: 57731 for the front hair and 63910 for the back hair hair
                    myCharacter.description.advance.hair.frontHair.style = "57731";
                    myCharacter.description.advance.hair.backHair.style = "63910";
                    // Change character style: The top is 58694, the bottom is 58700, the gloves are 60384, and the shoes are 58696
                    myCharacter.description.advance.clothing.upperCloth.style = "58694";
                    myCharacter.description.advance.clothing.lowerCloth.style = "58700";
                    myCharacter.description.advance.clothing.gloves.style = "60384";
                    myCharacter.description.advance.clothing.shoes.style = "58696";
                }
            });
            // Add a button method: Press keyboard "3" to synchronize the appearance of the character
            InputUtil.onKeyDown(Keys.Three, () => {
                myCharacter.syncDescription();
            });
            // Add a button method: Press keyboard "4" to clear the appearance of the character
            InputUtil.onKeyDown(Keys.Four, () => {
                myCharacter.clearDescription();
            });
        }
    }
}