After some trial and error, I went back to the GDQuest version of a multi-node state machine and I've at least managed to get the game running without any errors, but something in it seems to prevent everything from actually executing properly and I can't figure out what it is. From a debugger I made, I can tell that the states themselves are changing on button presses and the like, but I can't get the player to do anything, not even fall.
Just to test it out, I've so far only added Idle, Walk and Air scripts with very simple actions. The State/StateMachine scripts are literally the same as it is on GDQuest. I figured I could go from there and alter things to my needs once I figured out how to work it. State scripts are as follows:
Player:
class_name Player
extends KinematicBody2D
#VARIABLES
export var gravity: int = 4500;
export var maxFallSpeed: int = 2750;
var animState;
var velocity: = Vector2.ZERO;
func _ready():
animState = $AnimationTree.get("parameters/playback");
Idle:
#Idle
extends State
func enter(_msg := {}) -> void:
owner.velocity = Vector2.ZERO;
func physics_update(delta: float) -> void:
if !owner.is_on_floor():
state_machine.transition_to("Air");
if Input.is_action_pressed("left") or Input.is_action_pressed("right"):
state_machine.transition_to("Walk");
Walk:
#Walk
extends State
export var walk_speed: int = 1200;
func physics_update(delta: float) -> void:
if Input.is_action_pressed("right"):
owner.velocity.x = walk_speed;
elif Input.is_action_pressed("left"):
owner.velocity.x = -walk_speed;
else:
if owner.velocity.x == 0:
state_machine.transition_to("Idle");
Air:
#Air
extends State
func _physics_update(delta: float) -> void:
owner.velocity.y += owner.gravity * delta;
if owner.velocity.y > owner.maxFallSpeed:
owner.velocity.y = owner.maxFallSpeed;
owner.velocity = owner.move_and_slide(owner.velocity, Vector2.UP);
And again, through the debugger, I can tell that the states are being switched out. The starting state is Idle, but my player starts in the air so they fall at the beginning and it does say it's in the air state. If I disable the air state, then it'll say 'Idle' and if I press either movement option, it'll go to 'Walk,' so I know at least that's working, but the player themselves doesn't do anything except stay suspended in the air and play their idle animation on loop. I've double checked the state scripts (both my own and the ones on GDQuest) and as far as I can tell, everything seems fine, so I really don't know why it's not working.