I have this code for a plane script on mobile that hasn't been working right. The plane on mobile won't respond to the user's commands on direction via their movement on the touch screen. I'm trying to get the plane to move based on the touch location of the mobile user (i.e. where they tap/drag/whatever), such as if the player is dragging/touching right, it'll bank right, same for up, down, left, etc. This script does not respond to any of the mobile user's touch commands, and I have no idea why. I'm pretty new to working with mobile commands, so I'm not even sure if this is the right approach.
Basically, I need to find and detect the mobile equivalent of mouse.Hit, mouse.ViewSizeX, and mouse.X on PC.
Can someone assist me? Code is below
---Client sided code
local dY --- different approach I tried
local dX
local lastTouchTranslation = nil
local function setup_Touch(touchPositions, totalTranslation, velocity, state)
local difference
if state == Enum.UserInputState.Change or state == Enum.UserInputState.End then
difference = totalTranslation - lastTouchTranslation
end
lastTouchTranslation = totalTranslation
print(difference.X)
print(difference.Y) ---print statements won't work
dX = difference.X
dY = difference.Y
return difference.X, difference.Y ---I tried to get the code to work via a return of this function originally, to no avail, so I tried a different methoe with the dX and dY functions.
end
UserInputService.TouchPan:Connect(function() rem.onMouseMoved:FireServer(mouse.Hit,setup_Touch) end) --- this code is in a bigger function group that detects input on different devices
---Server sided code; code works on PC perfectly with mouse input, doesn't work so much with mobile input.
function GetBankAngle(M,ViewSizeX,X)
local VSX,X = ViewSizeX,X
local Ratio = (((VSX / 2) - X)/(VSX / 2))
Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
return math.rad(Ratio * 90)
end
function onMouseMoved(mouse,ViewSizeX,X)
local BankAngle = GetBankAngle(mouse,ViewSizeX,X)
if fly == true then
turn = true
while turn == true do
if heli ~= nil then
if heli.Parts:FindFirstChild("Engine") ~= nil then
heli.Parts.Engine.BodyGyro.cframe = (mouse * CFrame.Angles(0,0,BankAngle))
--Direction.cframe = (mouse.Hit * CFrame.Angles(0,0,BankAngle))
--heli.Parts.Engine.BodyGyro.cframe = mouse.Hit
end
end
wait(0.1)
end
end
end
local rem=script.Parent.Remotes
rem.onMouseMoved.OnServerEvent:connect(function(player,hit,ViewSizeX,X)
onMouseMoved(hit,ViewSizeX,X)
end)
---the output I am given says that they cannot perform arithmetic on nil values, that being the ViewSizeX and X values.
