Hi, I have a plane type of thing and am making variables local w,a,s,d true when input is detected. I have done this successfully for normal keys and thought I had done it correctly for mobile users. How can I fix this for mobile users? Thought Enum.KeyCode.Up would check this…
inputS.InputBegan:connect(function(input)
local code=input.KeyCode
if code==Enum.KeyCode.W or code==Enum.KeyCode.Up then
w=true
end
end)
You can use this to detect when a player taps on the screen
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.Touch) then
-- The user tapped anywhere on screen
end
end)
I made this mess but it only works with InputChanged:
local UserInputService = game:GetService("UserInputService")
local threshold = 1.5
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.Touch then return end
local idleX = false
local idleY = false
if input.Delta.X > threshold then
print("moving right")
elseif input.Delta.X < -threshold then
print("moving left")
else
idleX = true
end
if input.Delta.Y > threshold then
print("moving down")
elseif input.Delta.Y < -threshold then
print("moving up")
else
idleY = true
end
if idleX and idleY then
print("idle")
end
end)
Awesome, thank you! One thing if I may ask though, when I move the joystick to the end of the screen and then quickly let go, the part moves fine. However, if I move the joystick to the end of the screen and hold it there, suddenly the part vibrates like crazy while moving. The aim is that everything revers back to false once the joystick is released.
Do you know why this is happening? My first thought was that maybe idle was being switched on and off really quickly, but that can’t be, so now I’m not sure.
I tried messing around with that a bit but then the craft kind of stop starts a lot, quite strange. I’ll upload the current code in case there’s something I missed
local threshold = 3
inputS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Touch then
local idleX = false
local idleY = false
if input.Delta.X > threshold then
print("moving right")
d = true
elseif input.Delta.X < -threshold then
print("moving left")
a = true
else
idleX = true
d = false
a = false
end
if input.Delta.Y > threshold then
print("moving down")
s = true
elseif input.Delta.Y < -threshold then
w = true
print("moving up")
else
idleY = true
w = false
s = false
end
end
end)