Skip to content

Player States

DimensionWarped edited this page Feb 18, 2023 · 6 revisions

Player State Machine

Todo: Brief explanation of how the player is essentially managed with a finite state machine goes here

Player.tscn contains a child node 'States' which contains each player action state as a child of the master States node.

States

Normal

The nominal state for when the player is on the ground idling/walking/running/crouching/looking up.

Air

The standard air state for when a player is airborne, but not the result of a jump action. Distinguished from jump primarily in that it isn't ### paired with the jumping animation and the player will receive damage if hit.

Jump

As with air, but the result of the player jumping. While jumping, players usually (possible exception with Amy in the future, though she may just have a separate jump state) damage enemies as opposed to being hurt. They can also activate a character-dependent double-jump action.

Roll

If a player presses down in the normal state (or is holding down when they would transition from air/jump to rolling), the player will enter the rolling state. While rolling, the roll animation plays, the player gains speed more quickly while going down slopes, but loses much of his directional influence (holding against the direction of travel decelerates less, holding with the direction of travel accelerates less)

SpinDash

If while crouching (note that crouching takes place in the normal state and is not a separate state) the player presses an action button, they will enter the spindash phase and remain in it until they release the down button. Additional presses of the action button 'rev' the spindash, increasing its power. If down continues to be held without revving, the spindash power gradually decreases until it reaches the minimum power value. Upon release, the state will transition to roll and the player's ground speed will be set based on the amount of power the spindash gained from revving.

PeelOut

A Sonic-specific ability that is like spindash, but activated while looking up instead of crouching. Doesn't involve manual revving, instead the power increases of the course of about half a second until it reaches its maximum. The main difference is that the player transitions back to the normal state instead of the rolling state.

Animation

Animation is a catch-all state that can be used by objects and events that want to put a player into various animation states, but you don't want to assign any complex behavior to the state itself. See the CNZ Barrel gimmick, the Vertical Bar Gimmick, and the Vertical Pylon gimmick for examples.

Hit

When damaged by something and the player won't die from it, they go into a hurt state which involves getting knocked either left or right and after landing they transition back to the normal state with some amount of invulnerability time.

Die

If a player is crushed, falls below the boundary of the playfield/hits a death collider, or is damaged without rings / a shield (while not being player 2, who will always be hurt by this instead), the player will be killed. A brief animation will play out, the player will be thrown upwards slightly, and when the player exits the frame the current level will be reset from the most recently activated checkpoint post.

CorkScrew

Used by the CorkScrew gimmick. This functions similarly to normal while playing a unique animation, but with the player always being assumed to be in contact with the ground unless their absolute speed value falls below the value needed to maintain against gravity (which will make them fall off). The gimmick must be entered from the ground state to activate the corkscrew state.

JumpCancel

???

SuperStart

If a player has the ability to transform to their super form, they will switch to this state where they play out their transformation sequence before transitioning back to the air state.

Fly

Tails-specific action activated via double-jump. It's Tails flight, operates similarly to the air state with some parameters around gravity changed and has the ability to keep pressing jump to push upward until stamina runs out, at which point the animation changes. This state also handles Tails' swimming ability (which is the same as flying but again, with different parameters from the normal water physics). Another player can also be carried by Tails in this state, in which case they will behave similarly to if they were on a hanging bar gimmick.

Respawn

Tails-specific and also player 2 specific state where Tails flies back into frame after being left behind (this might need to be rethought if characters other than Tails can ever be set as player 2).

Hang

State used currently for players hanging from something such as a horizontal bar or Tails in flight mode. In this state, the player's position is set to wherever the item they are hanging from would set them and they are able to disembark by jumping.

Glide

Knuckles specific double jump action. Terminal velocity is dramatically decreased and the player constantly accelerates in the direction they are facing. Leads to WallClimb if the player impacts a wall.

WallClimb

Knuckles specific action that follows from glide. Allows the player to move up and down the side of vertical walls. This usually only works on tile walls in the main series and there are some surfaces that tend to prevent climbing.

Adding a new state

It is very likely that you will need to add new states in the course of developing new gimmicks, characters, and other features. In order to add a new state, a node with the name of the state should be added to the Player.tscn entity's 'States' node. The order of the nodes is important here and it must match that of the STATES enumerator in Player.gd. The length of the STATES enumerator should also always be consistent with the number of children of the States node in Player.gd. Note that within the enumerator, state names are capitalized. The names of the states in the enumerator should correspond to the names of the state nodes in Player.gd, but the name has no impact on the bahavior, only the order does. (This could be a potential target for future refactoring). State nodes must also link to a state script that inherits State.gd -- expect some improvements to the state system soon.