Reworked idle, lookaround and death to the states

This commit is contained in:
2026-02-01 23:51:37 +03:00
parent 37b5b698a6
commit 81d81ae103
16 changed files with 153 additions and 19 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ extends Node
@warning_ignore("unused_signal")
signal new_state(state: AbstractState)
signal switch_state(state: AbstractState)
func enter() -> void:
+18 -1
View File
@@ -2,9 +2,18 @@ class_name StateMachine
extends Node
@export var initial_state: AbstractState
var current_state : AbstractState
func _ready() -> void:
_connect_states()
if initial_state:
_change_state(initial_state)
func _process(delta: float) -> void:
if current_state:
current_state.process(delta)
@@ -15,8 +24,16 @@ func _physics_process(delta: float) -> void:
current_state.physics_process(delta)
func change_state(new_state: AbstractState) -> void:
func _change_state(new_state: AbstractState) -> void:
if current_state:
current_state.exit()
current_state = new_state
current_state.enter()
func _connect_states() -> void:
for child in get_children():
if not child is AbstractState: continue
var state := child as AbstractState
state.switch_state.connect(_change_state)