- What do I want to achieve
I really just want to know if whether or not (in the context of my scripts) attempting to differentiate players by the platform in which they are using matters when restricting both movement and jumping.
- What is the issue?
I have a system in my turn-based combat game that restricts player movement when fighting NPCs. Anyone who has played a turn-based combat game, or specifically JRPG, knows that 99% of the time, your character (and party) does not move position-wise while in combat.
Here is the system I am using thus far, which succeeds in restricting player movement on both PC and Mobile.
LocalScript:
local function onClientEventFunc(tbl, data)
if tbl.ActionType == "cutsceneTrigger" then
ContextActionModule.RestrictPlayerMovement(player)
TweenModule.FightIntro(player, camera, data, function()
print("Sequence is done")
end)
end
end
RemoteEventModule.event.OnClientEvent:Connect(onClientEventFunc)
Corresponding ModuleScript functions that matter for player movement:
-- Local Functions Used To Bind Movement
local function handleMovement(actionName, inputState, inputObject)
if actionName == "PlayerMovement" and inputState == Enum.UserInputState.Begin then
end
end
local function handleMobileMovement(actionName : string, inputState : Enum.UserInputState, inputObject : InputObject)
if actionName == "MobileMovement" and inputState == Enum.UserInputState.Begin then
end
end
local function disableJumpForMobilePlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
if UserInputService.TouchEnabled then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end
end
function ContextActionModule.RestrictPlayerMovement(player)
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled then
print("Most likely mobile")
ContextActionService:BindActionAtPriority("MobileMovement", handleMobileMovement, false, 4000, Enum.UserInputType.Touch)
disableJumpForMobilePlayer(player)
elseif UserInputService.MouseEnabled then
print("Most likely PC")
ContextActionService:BindAction("PlayerMovement", handleMovement, false, unpack(pcControlEnums))
end
end
I am aware that the differentiating is pretty lackluster and not full-proof, but given the fact that as I started thinking about it more, I am wondering about whether or not differentiating by platform even matters in this context.
For example, using this setup and not even bothering to differentiate between platform restricts movement for both Mobile Players and PC Players.
local function handleAllMovement(actionName : string, inputState : Enum.UserInputState, inputObject : InputObject)
if actionName == "AllMovement" and inputState == Enum.UserInputState.Begin then
end
end
function ContextActionModule.RestrictAllMovement(player)
ContextActionService:BindActionAtPriority("AllMovement", handleMovement, false, 4000, unpack(allControlEnums))
disableJumpForMobilePlayer(player)
end
If anyone knows a better way to do this, whether differentiating even matters, or has any thoughts/advice of their own, it is appreciated. Thanks.