Alrighty sooo, i have a section in a game im making where, lets say i wish to disable the player moving left, back and foward, only allowing them to move right.
Now i’ve managed to get a rly cool system up and, using Enum.PlayerActions.CharacterLeft, i can disable the player’s left movements… on pc… for some odd reason on mobile, i can walk around and do whatever i wanna freely
I’ve checked and looked into disabling .Touch in UserInputTypes but… that disables ALL controls, im not too sure how to limit the direction.
Simply put: my question is, can i disable a mobile player’s ability to use specific directions or must i find a work-around to ensure mobile players (and possibly players on other devices) have specific controls disabled?
That should be all!!
3 Likes
You should, instead of trying to disable certain core input aspects for mobile players, simply detect if the player is on mobile or not.
Me personally, I detect if a player is on mobile by this one singular line of code:
self.Mobile = not (UserInputService.KeyboardEnabled and UserInputService.MouseEnabled)
Once you can detect if the player is on mobile, use this piece of code when writing your movement scripts to disable the script working.
Hope this should solve your issue.
Also, I couldn’t help notice that you’re using ContextActionService.. and I wanted to reccommend that you should take a look at ROBLOX’s new Input Action System (which is object-based input). It works very similar to Context Action Service and is ROBLOX’s newest form of input. I personally think it’s brilliant.
Good luck with your coding!
Hmm, alright!! I’ll take a look at input action system!! My goal here was simply to match the pc expirence of only having one available direction with mobile so if i can do this via this new system ill mark it as a solution!
Alright, so i’ve been having a look and play and cant seem to figure out quite exactly how this system works.
As a template, what im aiming for is simply to prevent the player moving in 3/4 directions, on all devices, as of current, it only prevents PC movement whereas mobile can move freely. My goal is also to prevent the movement of mobile devices in this direction.
If you would, could you explain further how to use this system in order to make something like this? As i cant quite seem to understand it myself based on the documentation nor how to replace contextactionservice with this.
you can achieve this easily if you just edit the some of the modules under ControlModule, this is the DynamicThumbstick, mobile’s default movement module, edited to what you’re looking for:
function DynamicThumbstick:DoMove(direction: Vector3)
local currentMoveVector: Vector3 = vector.create(math.max(direction.X, 0), 0, 0) --direction
-- Scaled Radial Dead Zone
local inputAxisMagnitude: number = currentMoveVector.Magnitude
if inputAxisMagnitude < self.radiusOfDeadZone then
currentMoveVector = ZERO_VECTOR3
else
currentMoveVector = currentMoveVector.Unit*(
1 - math.max(0, (self.radiusOfMaxSpeed - currentMoveVector.Magnitude)/self.radiusOfMaxSpeed)
)
currentMoveVector = Vector3.new(currentMoveVector.X, 0, currentMoveVector.Y)
end
self.moveVector = currentMoveVector
end
Ahh i see!! Appologies for the late reply, ill try this out in my game and mark it as solution if i can get it to work!
1 Like
Okay, did some playing and managed to get it so mobile players can only move right (vector.create(math.max(direction.X, 0), 0, 0)), aswell as backwards (vector.create(0, math.max(direction.Y, 0), 0))
However i cant seem to find a way to make it so the player can only go left or forwards
Are you able to follow up with some way of doing this?
Again, very thankful for the help! :3
try using math.clamp instead of math.max, it should be easier to read
-- left and right
vector.create(math.clamp(direction.X, -1, 1), 0, 0)
-- right and forward, i think
vector.create(math.clamp(direction.X, 0, 1), 0, math.clamp(direction.Z, 0, 1))
two examples i am writing from the top of my head, just to help give you an idea:)
i attempted to use the first one and now nothing exactly happens… i tried changing the -1 and 1 to see if that would unfreeze it but nothin seems to happen…
For extra clarification, this segment im making limits the player’s movement to a single direction, and sometimes this direction changes, which i have a system to account for, im just trying to get a way to allow only moving in 1 direction on all 4 main directions
(which i do have a way to swap between these presets, my only struggle is getting said presets to only allow moving in that one direction)
I appreciate the fast reply:D
apparently the direction vector isn’t normalized, i thought it was SORRY, these examples should work
local normalizedDirection = direction.Unit
-- left and right
vector.create(math.clamp(normalizedDirection.X, -1, 1), 0, 0) * direction.Magnitude
-- forward and backwards
vector.create(math.clamp(0, math.clamp(normalizedDirection.Y, -1, 1), 0) * direction.Magnitude
-- pretty much the default
vector.create(math.clamp(normalizedDirection.X, -1, 1), math.clamp(normalizedDirection.Y, -1, 1), 0) * direction.Magnitude
the direction vector is also apparently a vector2, despite being annotated as a vector3, so thats weird, doesnt really matter doe
Yes!! this worked wonderfully!! Tho, the fowards and backwards has an aditional math.clamp which errored, and removing the math.clamp at the start fixed it!! Either way, thank you so much for your help!! This has been an absolute life saver :3
1 Like