Skip to content
Character Basic State

Character Basic State

It takes about 15 minutes to read this article

This article outlines the basic states of a character, the switching and performance effects of each basic state, and what functions can be performed using the basic states of a character.

Basic State Introduction

The basic state of a character refers to the state in which the character uses certain basic abilities, which enables the character to perform corresponding actions and allows the character to be in a stable state for a period of time. This state is the basic state of the character. For example, when the character moves on the ground, the character will play the running action. At this time, the character is in the Running state.

Character Basic State

There are currently 9 basic character states. Player can switch basic states through the API, or automatically switch to the corresponding basic state through basic abilities such as jumping.

Enumeration nameEnumeration numberApplication description
None0Cancel the character's complex movement mode and adopt a simple movement mode state
Running1The state of the character when moving on the ground
Flying2The state of the character when flying in the air
Swimming3The state of the character when swimming
Jumping4The state of the character when performing the jump function
Freefall5The state of the character when fall in the air
Landed6The state of the character when it touches the ground after free fall
Ragdoll7The state of the character when in ragdoll state
Crouching8The state of the character when crouching

Running state

state definition: state effect when the character is on the ground, moving or stationary.

state description: Running state is the final state after most character switch state, and it is also the most basic state of the character. For example, after the character switches to the free fall state, it will touch the ground after a period of time to trigger the landing state, and finally switch to the running state. We can also actively switch the running state to reset the character's current basic state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: running state
chara.changeState(CharacterStateType.Running)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: running state
chara.changeState(CharacterStateType.Running)

Flying state

State definition: The state of the character when it is moving or stationary in the air while ignoring gravity.

state description: The flying state is a relatively independent character state. After the character switches to the flying state, the movement and standby animation in the flying state will be played automatically. We need to actively switch to other basic states of the character to cancel the character's flying state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: flying state
chara.changeState(CharacterStateType.Flying)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: flying state
chara.changeState(CharacterStateType.Flying)

Swimming state

state definition: state effect of the character when it is in water, moving or stationary.

state description: The swimming state is a relatively independent character state. After the character switches to the swimming state, the movement and standby animation in the swimming state will be played automatically. We need to actively switch to other basic states of the character to cancel the character's swimming state.

image-20240828135740331

Note: We provide the logic object of the swimming area in the logic object . When entering the swimming area, the Player will automatically switch to the swimming state. When leaving the swimming area, the Player will automatically switch to free fall state and eventually change to running state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: swimming state
chara.changeState(CharacterStateType.Swimming)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: swimming state
chara.changeState(CharacterStateType.Swimming)

Jumping state

state definition: The state effect of the character when performing the jump function.

state description: The jumping state is not a continuous state, but a transitional state. When the character performs the jumping function, it will switch to the jumping state. After reaching the set jumping height, it will automatically switch to the free falling state, and finally land and enter the Running state.

Note: When the character actively switches to the jumping state, the character will directly execute the jumping function.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: jump state
chara.changeState(CharacterStateType.Jumping)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: jump state
chara.changeState(CharacterStateType.Jumping)

Free fall state

state definition: The state effect of the character fall from the air under the influence of gravity.

state description: The free fall state is not a continuous state, but a transitional state. When the character falls from a high altitude, it will switch to the free fall state. When the character touches the ground, it will trigger the landing state and finally enter the running state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: free fall state
chara.changeState(CharacterStateType.Freefall)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: free fall state
chara.changeState(CharacterStateType.Freefall)

Landing state

State definition: The instantaneous state of the character after fall from a high altitude and touching the ground.

state description: The landed state is not a continuous state, but a transition state. When the character touches the ground in the air, it will switch to the landed state, play the landing animation, and finally enter the running state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: landing state
chara.changeState(CharacterStateType.Landed)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: landing state
chara.changeState(CharacterStateType.Landed)

Ragdoll state

State definition: The character is not control by the Player and is in the state effect of object simulation.

state description: When a character is knocked away or knocked to the ground by external force, the character state is generated to simulate the real effect in reality. In this state, the character is not control by the Player , and the character model will be affected by external force, producing some physical effects. The ragdoll state is a relatively independent character state. When the character switches to the ragdoll state, it will automatically switch to the ragdoll effect. We need to actively switch to other basic states of the character to cancel the character's ragdoll state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: ragdoll state
chara.changeState(CharacterStateType.Ragdoll)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: ragdoll state
chara.changeState(CharacterStateType.Ragdoll)

Crouching state

state definition: The state effect of the character when performing the crouch function.

state description: The crouching state is a relatively independent character state. After the character switches to the crouching state, the movement and standby animation in the crouching state will be played automatically. We need to actively switch to other basic states of the character to cancel the character's crouching state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: crouch state
chara.changeState(CharacterStateType.Crouching)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: crouch state
chara.changeState(CharacterStateType.Crouching)

None

State definition: The character will cancel the complex movement logic, and users are required to customize the action state and movement effect state.

State description: The no state is a relatively independent character state. When the character switches to the no state, the character will turn off the complex movement logic, and the Player needs to customize the action stance and movement effect. We need to actively switch to other basic states of the character to cancel the character's stateless state.

Sample script:

ts
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: no state
chara.changeState(CharacterStateType.None)
//Get the Player character
let chara = Player.localPlayer.character
//If it is an old project, you need to reset the action asset
chara.loadStance("216081").play();
//Set the character state: no state
chara.changeState(CharacterStateType.None)

enable/ disable state

We provide the function of enable and disable basic states. If we disable a certain basic state, the character will not be able to switch to the disable basic state, and the character will maintain the effect of the previous basic state before the switch.

Sample script:

ts
// disable the character's running state
chara.setStateEnabled(CharacterStateType.Running,false);
// enable the character's running state
chara.setStateEnabled(CharacterStateType.Running,true);
// disable the character's running state
chara.setStateEnabled(CharacterStateType.Running,false);
// enable the character's running state
chara.setStateEnabled(CharacterStateType.Running,true);

Get state and switch state callback

We provide functions for obtaining the current state of the character, as well as callbacks for when the character switches states, so that you can add some experience logic when the character switches states.

Sample script:

ts
//Get the current Player character
Player.asyncGetLocalPlayer().then((player) => {
    //When the character state change, call back the character previous state and current state
    chara.onStateChanged.add((pre, curr)=>{
        //Print information
        console.log(`pre: ${pre} curr: ${curr}`);
    })
});
//Get the current Player character
Player.asyncGetLocalPlayer().then((player) => {
    //When the character state change, call back the character previous state and current state
    chara.onStateChanged.add((pre, curr)=>{
        //Print information
        console.log(`pre: ${pre} curr: ${curr}`);
    })
});