Hey there, I am looking to create a StateManager for a combat system. For example,
IsStunned
IsFighting
IsDashing
IsJumping
What is the best way to go about that and for example. If the user is stunned and there is an ability to evade. What would be the simplest way to cancel the “IsStunned” and put him into the state of “IsEvading”.
I wanted to also add that I have a hard time controlling the walkspeed and jump height of the user.
For example, while the user IsStunned, he can’t walk or jump. The current way of preventing the user from walking while being stunned was to constantly loop on the character’s attribute and check if the user IsStunned… That was one way of doing it.
Because let’s say I wanted to prevent dashing while being stunned. I would do this here, but it doesn’t seem like the best option.
This would be the start of the dashing function
local function dash(initialDirection, directionKey)
if isDashing or character:GetAttribute("IsPunching") or character:GetAttribute("Disable") or character:GetAttribute("IsBlocking") or character:GetAttribute("IsStunned") or tick() - lastDashTimeAnyDirection < dashDelayBetweenDirections then return end
character:SetAttribute("IsDashing", true)
local currentTick = tick()
local dashCooldown = lastDashTimes[directionKey] + cooldown
if currentTick < dashCooldown then
character:SetAttribute("IsDashing", false)
return
end