I have this Motorcycle for mobile that uses ContexActionService
it works but when I hold on to a control button and move my touch on different location while holding, the UserInputState is still not becoming an End
is there a way to determine if the user’s holding touch from a button went outside from its size?
This is my current script that doesn’t seem to work:
-- Some of actions does not have the isHovering because I was testing it first.
local function CASContext(actionName, state : Enum.UserInputState, inputObject)
if state ~= Enum.UserInputState.Cancel then
print(state)
local Data = {
Context = nil,
}
local isHovering = state == Enum.UserInputState.Change
--print(isHovering)
if actionName == _ACTION_NAMES[1] then
-- Horn
if state == Enum.UserInputState.Begin then
Data.Context = "motorcycle-horn"
MotorcycleRemote:FireServer(Data)
end
elseif actionName == _ACTION_NAMES[2] then
-- Lights
if state == Enum.UserInputState.Begin then
Data.Context = "motorcycle-lights"
MotorcycleRemote:FireServer(Data)
end
elseif actionName == _ACTION_NAMES[3] then
if state == Enum.UserInputState.Begin or isHovering then
-- key down
Data.Context = "motorcycle-forward"
Data.State = "key-down"
MotorcycleRemote:FireServer(Data)
elseif state == Enum.UserInputState.End or not isHovering then
-- key up
Data.Context = "motorcycle-forward"
Data.State = "key-up"
MotorcycleRemote:FireServer(Data)
end
elseif actionName == _ACTION_NAMES[4] then
if state == Enum.UserInputState.Begin then
-- key down
Data.Context = "motorcycle-reverse"
Data.State = "key-down"
MotorcycleRemote:FireServer(Data)
elseif state == Enum.UserInputState.End then
-- key up
Data.Context = "motorcycle-reverse"
Data.State = "key-up"
MotorcycleRemote:FireServer(Data)
end
elseif actionName == _ACTION_NAMES[5] then
if state == Enum.UserInputState.Begin and isHovering then
-- key down
Data.Context = "motorcycle-left"
Data.State = "key-down"
MotorcycleRemote:FireServer(Data)
elseif state == Enum.UserInputState.End and not isHovering then
-- key up
Data.Context = "motorcycle-left"
Data.State = "key-up"
MotorcycleRemote:FireServer(Data)
end
elseif actionName == _ACTION_NAMES[6] then
if state == Enum.UserInputState.Begin then
-- key down
Data.Context = "motorcycle-right"
Data.State = "key-down"
MotorcycleRemote:FireServer(Data)
elseif state == Enum.UserInputState.End then
-- key up
Data.Context = "motorcycle-right"
Data.State = "key-up"
MotorcycleRemote:FireServer(Data)
end
end
end
end