[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:
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.
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.
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.
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
@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 ​
↳
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:
@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:
@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
@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
@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 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
Returns ​
| Set character flight brake rate Parameters ​
|
brakingDecelerationSwimming ​
• | • | ||||
---|---|---|---|---|---|
Get the character's swimming brake speed 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
Returns ​
| Set the character's swimming braking speed Parameters ​
|
brakingDecelerationWalking ​
• | • | ||||
---|---|---|---|---|---|
Set the character walking brake rate 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
Returns ​
| Set the character walking brake rate Precautions It only takes effect when the enable brake friction groundFriction is enabled. Parameters ​
|
canStandOn ​
• | • | ||||
---|---|---|---|---|---|
Get whether the character can be standing by other Player 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
Returns ​
| Set whether the character can be stood up by other players. Parameters ​
|
capsuleCorrectionEnabled ​
• | • | ||||
---|---|---|---|---|---|
Get whether the character is currently using capsule correction 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
Returns ​
| Set whether the character is currently using capsule correction Parameters ​
|
characterType ​
• | ||
---|---|---|
What type of character is obtained 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
Returns ​
|
collisionExtent ​
• | • | ||||
---|---|---|---|---|---|
Obtain the shape and size of the collision body of the package character 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
Returns ​
| Set the shape and size of the wrapped character collision body Parameters ​
|
collisionShape ​
• | • | ||||
---|---|---|---|---|---|
Obtain the collision shape of characters (capsule shape, ball shape, box shape) 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
Returns ​
| Set character collision shape (capsule shape, spherical shape, box shape) Parameters ​
|
collisionWithOtherCharacterEnabled ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| Set whether the character can currently collide with other characters. Parameters ​
|
complexMovementEnabled ​
• | • | ||||
---|---|---|---|---|---|
Whether to enable the complex mobile policy Returns ​
| Whether to enable the complex mobile policy Parameters ​
|
crouchedHeight ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| Set the height of the collision box when the character is crouch. Parameters ​
|
currentAnimation ​
• | ||
---|---|---|
The currently playing animation object Returns ​
|
currentStance ​
• | ||
---|---|---|
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
Returns ​
|
currentSubStance ​
• | ||
---|---|---|
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
Returns ​
|
description ​
• | ||
---|---|---|
Character appearance configuration 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
Returns ​
|
displayName ​
• | • | ||||
---|---|---|---|---|---|
Get character Name 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
Returns ​
| Set character Name Parameters ​
|
driftControl ​
• | • | ||||
---|---|---|---|---|---|
Get the flexibility of character in the air 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
Returns ​
| Set the flexibility of the character in the air Parameters ​
|
forceUpdateMovement ​
• | ||
---|---|---|
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
Parameters ​
|
gravityScale ​
• | • | ||||
---|---|---|---|---|---|
Obtain the magnification of gravity 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
Returns ​
| Set the magnification of gravity Parameters ​
|
groundFriction ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| 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 ​
|
groundFrictionEnabled ​
• | • | ||||
---|---|---|---|---|---|
Obtain separate brake friction status 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
Returns ​
| Set separate brake friction state Parameters ​
|
horizontalBrakingDecelerationFalling ​
• | • | ||||
---|---|---|---|---|---|
Obtain the character's descent braking rate 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
Returns ​
| Set the character's descent braking rate Parameters ​
|
isCrouching ​
• | ||
---|---|---|
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
Returns ​
|
isDescriptionReady ​
• | ||
---|---|---|
Get whether the current character appearance is ready 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
Returns ​
|
isJumping ​
• | ||
---|---|---|
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
Returns ​
|
isMoving ​
• | ||
---|---|---|
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
Returns ​
|
jumpMaxCount ​
• | • | ||||
---|---|---|---|---|---|
Get the maximum number of hops a character can make 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
Returns ​
| Set the maximum number of jumps for character Parameters ​
|
maxAcceleration ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum acceleration of the character 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
Returns ​
| Set the maximum acceleration of the character Parameters ​
|
maxFallingSpeed ​
• | • | ||||
---|---|---|---|---|---|
Set the maximum descent speed of the character 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
Returns ​
| Set the maximum descent speed of the character Parameters ​
|
maxFlySpeed ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum flight speed of the character 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
Returns ​
| Set the maximum flying speed of character Parameters ​
|
maxJumpHeight ​
• | • | ||||
---|---|---|---|---|---|
Get the maximum jump height of character 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
Returns ​
| Set the maximum jump height of character Parameters ​
|
maxStepHeight ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum height that the character can cross 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
Returns ​
| Set the maximum height that a character can cross Parameters ​
|
maxSwimSpeed ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum swimming speed of the character 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
Returns ​
| Set the maximum swimming speed for the character Parameters ​
|
maxWalkSpeed ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum walking speed of the character 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
Returns ​
| Set the maximum walking speed of the character Parameters ​
|
maxWalkSpeedCrouched ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| 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 ​
|
meshPositionOffset ​
• | • | ||||
---|---|---|---|---|---|
Obtain the offset of the mesh relative to the character coordinate points Returns ​
| Set the offset of the mesh relative to the character coordinate points Parameters ​
|
meshRotationOffset ​
• | • | ||||
---|---|---|---|---|---|
Get the offset of mesh relative to character rotation Returns ​
| Set the offset of mesh relative to the rotation of character Parameters ​
|
moveFacingDirection ​
• | • | ||||
---|---|---|---|---|---|
Obtain the direction of the character's movement face
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
Returns ​
| Set the character to face the direction when moving. Parameters ​
|
movementDirection ​
• | • | ||||
---|---|---|---|---|---|
Get the positive direction of character motion
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
Returns ​
| Set the positive direction of character movement Parameters ​
|
opacity ​
• | • | ||||
---|---|---|---|---|---|
Obtain single-layer transparency of the character Returns ​
| Set character single layer transparency Parameters ​
|
outOfWaterVerticalSpeed ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| Speed in vertical direction when leaving water Parameters ​
|
overheadUI ​
• | ||
---|---|---|
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
Returns ​
|
physicsEnabled ​
• | • | ||||
---|---|---|---|---|---|
Get physical simulation status of character Returns ​
| Set character physical simulation state Parameters ​
|
ragdollEnabled ​
• | • | ||||
---|---|---|---|---|---|
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
Returns ​
| 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 ​
|
rotateRate ​
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum turning speed of the character 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
Returns ​
| Set the maximum turning speed for the character Parameters ​
|
velocity ​
• | ||
---|---|---|
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
Returns ​
|
walkableFloorAngle ​
• | • | ||||
---|---|---|---|---|---|
Get the maximum angle that character can walk 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
Returns ​
| Set the maximum angle at which the character can walk Parameters ​
|
nameDisplayDistance ​
• | • | ||||
---|---|---|---|---|---|
Get the visible distance of the overhead display names of all characters in the current client. Precautions Display Name Visible Distance Returns ​
| 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 ​
|
nameVisible ​
• | • | ||||
---|---|---|---|---|---|
Retrieve whether the overhead display names of all characters in the current client are visible. Returns ​
| Set whether the top display names of all character on the current client are visible Parameters ​
|
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 Vector | Usage: impulse of the application |
---|---|
ignoreMass? boolean | Usage: 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:
@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 Vector | Usage: 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:
@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 GameObject | Attached object |
---|---|
slotName NonHumanoidSlotType HumanoidSlotType | Slot 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:
@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 CharacterStateType | New 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? boolean | Usage: whether to clear appearance data default: true |
---|---|
slotAndDecoration? boolean | Usage: 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:
@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? boolean | Do you want to destroy these separated slots |
param.slotName? HumanoidSlotType | Usage: 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:
@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 GameObject | Object 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:
@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 string | MorphName |
---|
Returns ​
Vector | @networkStatus Usage: Dual ended |
---|
getCurrentState ​
• getCurrentState(): CharacterStateType
other
Get the current status of the character
Returns ​
CharacterStateType | Current role status |
---|
Usage example: Press E to view the current status and print
@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 ​
CharacterDescription | Copy 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:
@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 HumanoidSlotType | Usage: Slot name |
---|
Returns ​
Vector | Coordinate 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:
@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 string | MorphName 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:
@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 number | Model vertex index range: determined based on the data of the skeleton mesh object vertices. Type: integer |
---|
Returns ​
Vector | Vertex 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:
@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 Vector | Tracking 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:
@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 string | Usage: 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 ​
Animation | Animation 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:
@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 string | Basic posture resource ID range: The string length depends on the specific resource ID |
---|
Returns ​
Stance | Basic 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:
@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 string | Attitude resource ID or animation resource ID range: The length of the string depends on the specific resource ID |
---|
Returns ​
SubStance | Secondary 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:
@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 CustomShapeType | Shape of collision body (capsule, spherical, box) |
---|---|
collisionExtent Vector | The 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.
@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 [] CharacterDescription | Usage: 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:
@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 CharacterStateType | Character Status |
---|---|
enabled boolean | Whether 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 number | Usage: 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:
@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? boolean | Usage: Role synchronization default: true |
---|---|
slotAndDecoration? boolean | Usage: 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:
@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();
});
}
}
}