Godot Version
4.3
Question
Hello
Recently I’ve been trying to make a fighting game on godot, and have been following https://www.youtube.com/watch?v=gtrOIQtnJmI&t=493s to make the game.
Unfortunately, I have encountered many issues mainly in the stack frames.
I am very new to Godot and I don’t know how to fix these issues.
Player Code:
extends CharacterBody2D
class_name LachiePlayer
@onready var state_machine: StateMachine = $FSM
@onready var anim: AnimatedSprite2D = $Animation
func _ready(): state_machine.init() #<— theres an issue here
func _process(delta): state_machine.process_frame(delta)
func _physics_process(delta): state_machine.process_physics(delta)
func _input(event): state_machine.process_input(event)
Player Idle Code:
extends PlayerState
class_name LachieIdle
func enter() → void:
Lachie.anim.play(idle_anim) #<-- there is an issue here
State Machine Code:
extends Node
class_name StateMachine
var current_state: State
@export var initial_state : State
func init() → void: change_state(initial_state) #<---- theres an issue here
func process_frame(delta: float) → void:
var new_state: State = current_state.proccess_frame(delta)
if new_state: change_state(new_state)
func process_input(event: InputEvent) → void:
var _new_state: State = current_state.process_input(event)
func process_physics(delta: float) → void:
var new_state: State = current_state.process_physics(delta)
if new_state: change_state(new_state)
func change_state (new_state: State) → void:
if current_state: current_state.exit()
current_state = new_state
current_state.enter() #<-- there is an issue here aswell
States:
extends Node
class_name State
func enter() → void:
pass
func exit() → void:
pass
func proccess_frame(_delta) → State:
return null
func process_input(_event) → State:
return null
func process_physics(_delta) → State:
return null
Player State Class:
class_name PlayerState
extends State
@onready var Lachie: LachiePlayer = get_tree().get_first_node_in_group(“LACHIE”)
var idle_anim: String = “Idle”