Skip to content

Player Controller

chris edited this page Jul 21, 2026 · 29 revisions

System Summary

The player controller allows the user to move the player while testing a level. It handles player physics and interactions with different tile types using ray casts, and it applies any custom properties set by the user in the editor state. The player properties are organized into several presets that can be chosen to aid the user's direction.


Connected Systems

Connecting Systems:


Related Controls

List of related controls.

Key(s):

  • Space, W or ↑: Jump, either from the ground or while coyote time is still left.
  • A or ←: Move Left
  • D or →: Move Right
  • S or ↓: Drop through One-Way tiles if the ability to do so is enabled.

Bugs

  • Slopes may cause odd behaviors, such as the player moving upwards more slowly than downwards.

Feature List / Breakdown of Features

Player Controlling:

  • The player is always able to jump and move. If toggled, the player can also wall jump, double jump, and slide on walls that aren't composed of ice tiles.
  • Friction and air control alter how quickly the player can accelerate or decelerate on ice tiles or in midair.

Player Finite State Machine:

  • The player's animations and abilities are determined by a Finite State Machine.
  • Player's state moves between Grounded, Running, Jumping, Bouncing, Falling, Sliding, Victory, and Dead.

Player Interaction:

  • Using ray casts, the player will interact differently with each tile type, depending on what side the player makes contact from.
  • The player cannot exit the boundary of the level due to the border. They also cannot wall jump on the border.

Modifiable Values:

  • All numeric stats and toggles (wall jump, double jump movement speed, fall speed, jump height, FPS, coyote time, and air control) can be modified. This affects how the player controls and allows for many combinations of properties.
  • Four presets exist to auto-set the player's stats according to an archetype.

Important Variables

  • **currentState : PlayerState = Stores the player's current state to play animations with

  • maxHealth : int = The maximum amount of health the player can have.

  • groundSpeed : float = The speed of the player when on the ground.

  • baseAcceleration : float = The speed of the player's acceleration when starting movement or when continuing movement in current direction.

  • baseDeceleration : float = The speed of the player's deceleration when moving in the opposite direction or when movement is stopping..

  • jumpHeight : float = The amount of tiles the player can jump.

  • airControl : float = The amount of control the player has midair.

  • fallSpeed : float = How quickly the player falls in the air.

  • coyoteTime : float = How long after stepping off a platform the player can still jump.

  • isCoyoteActive : bool = true if coyote time remaining is > 0

  • isPlayerGrounded : bool = true if the player body is on a solid surface

  • wallJumpConditionsMet : bool = true if player is lined up with wall on either side

  • wallSlideConditionsMet : bool = true if wallJumpConditions is met and player holds input in direction of detetected wall

  • playerMovementPreset : PlayerMovementPreset = The currently selected and applied player movement preset.

  • oneways: bool = Determines if the player can drop through oneway tiles.

  • doubleJump: bool = Determines if the player can double jump.

  • wallJump: bool = Determines if the player can jump and slide on walls.

  • wallJumpStrength: float = Determines the player's wall jump strength.

  • wallJumpDecay: bool = Determines if the player starts falling when jumping off the same wall.

Important Enums

  • WallDirection LEFT, RIGHT, NONE

  • PlayerState GROUNDED, RUNNING, JUMPING, WALL_JUMPING, FALLING, SLIDING, BOUNCING, TILE_EFFECT_BOUNCE, HURT, DEAD, VICTORY

Important Functions

Name of the most important functions, their parameters, and what they do.

  • func set_state( state : PlayerState, function : Callable = Callable()) -> void: handles state transitions through a match statement, can think of it like a _ready func for entering a new player state that sets up all important variables, Callable function able to be passed in if an external function needs to be called when setting the state

  • func apply_state_logic( delta: float ) -> void: Handles state every frame state logic through a match statement, can think of it like a _process func for running the current player state

  • func walk() -> void: Handles left and right movement for the player, including deceleration when there is no input. The airControl variable also effects the movement speed of the player in air within this function.

  • func jump() -> void: Handles the jumping of the player based on the jumpHeight.

  • func wall_jump() -> void: Holds wall jumping logic to be called in the transition to the wall jump state

  • Func resolve_wall_jumps() -> void: Uses side raycast array to detect wall based on ray directions and set the values of wallDirection & the wall + wallslide condition booleans mentioned above

  • func take_damage(amount: int) -> void: Deals amount damage to the player based on their health, and if their health is <= 0, executes die().

  • func detect_tiles() -> void: Detect the object the player is touching, including enemies or tiles, and apply the correct effects based on that collision.

  • func detect_enemies(body: Node2D) -> void: If an enemy is touching the player take damage.

  • func detect_projectiles(area: Area2D) -> void: If a projectile is touching the player take damage.

  • func bounce() -> void: Exerts a vertical force on the player.

  • func apply_preset(preset: PlayerMovementPreset) -> void: Sets all of the player's values to those of the selected preset.

  • func check_out_of_bounds() -> bool: Checks if the player is outside of the bounds of the level.


Future Work / Risks

List and description of upcoming work/risks.

Future Work:

  • None currently

Risks:

  • None currently

Miscellaneous Notes

A place for miscellaneous notes pertaining to this system.

  • None

Clone this wiki locally