I made a pretty simple state class that does what it’s supposed to do (handles changing the players state), however, I feel like it can be improved I’m just not entirely sure how since I don’t have too much experience with state machines.
function State.new(fighter)
local self = setmetatable({},State)
self.input = fighter.input
self.states = FSM.create({
initial = "Neutral",
events = {
{name = "Neutral", from = "*", to = "Neutral"},
{name = "Crouch", from = "Neutral", to = "Crouch"},
{name = "Jump", from = "Neutral", to = "Jump"},
{name = "Land", from = "Jump", to = "Neutral"},
{name = "Hit", from = "*", to = "Hit"},
{name = "Special", from = "*", to = "Special"},
{name = "Throw", from = "Neutral", to = "Throw"},
{name = "Recovery", from = "Hit", to = "Recovery"},
{name = "Knockdown", from = "*", to = "Knockdown"},
{name = "Taunt", from = "Neutral", to = "Taunt"},
},
})
Movement.onLanded:Connect(function()
self.states:Land()
end)
RunService:BindToRenderStep("State",Enum.RenderPriority.Character.Value,function()
self:update()
end)
return self
end
function State:update()
local currentState = self.states.current
if self.input:isKeyDown(self.input.keybinds.Down) and currentState ~= "Crouch" then
self.states:Crouch()
end
if self.input:isKeyDown(self.input.keybinds.Up) and currentState ~= "Jump" then
self.states:Jump()
end
if not self.input:isKeyDown(self.input.keybinds.Down) and not self.input:isKeyDown(self.input.keybinds.Up) and
currentState ~= "Neutral" and currentState ~= "Jump" then
self.states:Neutral()
end
end