Godot Version
State Machine Base:
extends Node
class_name State_Machine
var CS : State
var NS : State
## Put parent here.
var parent
## Change new state, if current state is different to new state,
## then apply exit rules, change current state to new state, and apply enter rules.
func state_check() -> void:
if (CS != NS):
CS.exit()
CS = NS
CS.enter()
return
## Apply state rules.
func state_process() -> void:
NS = CS.process_event(get_process_delta_time())
# FIXME: need to figure out how to get input to this.
NS = CS.process_physics()
return
## Force state change.
## NOTE: use only for switching to death states and things like that.
## Possibly could result in problems.
func state_forcechange(state: State) -> void:
CS = state
NS = state
return
Player:
extends CharacterBody2D
class_name Player
# Regular variables.
@export var SS : State
const speed_walk : float = 300.0
const speed_run : float = 500.0
# Onready variables.
@onready var SM : State_Machine = $"State Machine"
func _ready():
SM.CS = SS
func _physics_process(_delta) -> void:
SM.state_process()
SM.state_check()
move_and_slide()
return
Player State Machine:
extends State_Machine
func _ready():
parent = $".."
Question
For my state machine in need to get player inputs to my process_inputs function but i'm not sure how to do that.