InputBeginner
Combat Controls with OwlAction
A priority-based ActionMap driving attack/block/dodge, cleanly swapped out for a menu control scheme.
OwlActionActionMapContextActionService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Owl = require(ReplicatedStorage.OwlKnit.Owl)
local OwlAction = Owl.Util.Action
local CombatController = Owl.CreateController({ Name = "CombatController" })
function CombatController:OwlInit()
self.CombatMap = OwlAction.CreateActionMap({
Name = "Combat",
Actions = {
Attack = { Enum.UserInputType.MouseButton1 },
Block = { Enum.KeyCode.F },
Dodge = { Enum.KeyCode.LeftShift, Enum.KeyCode.ButtonR2 },
},
Priority = Enum.ContextActionPriority.High.Value,
})
end
function CombatController:OwlStart()
self.CombatMap:Bind("Attack", function(state)
if state == "Begin" then self:PerformAttack() end
end)
self.CombatMap:Bind("Dodge", function(state)
if state == "Begin" then self:PerformDodge() end
end)
self.CombatMap:Enable()
end
function CombatController:EnterMenu()
self.CombatMap:Disable() -- > // frees the keys for a Menu ActionMap
end
return CombatControllerWhat's happening here
- Dodge lists two inputs (LeftShift and ButtonR2) either one triggers the same action, covering keyboard and gamepad from one Bind call.
- Nothing is bound to ContextActionService until :Enable() runs creating the ActionMap alone has no effect on input.
- :Disable() frees every key this map claimed, the clean way to swap to a Menu ActionMap without manual UnbindAction calls.
Related docs