I'm working my butt off trying to make my guns mobile compatible. And I'll be posting many problems over the next few days or weeks.
So, here's my problem. I have this code that makes my arms go up and down with your camera when you are in FPS. This works perfectly fine on computer. But once you get on mobile, everything is going wrong, that is, until you tap all over the screen and move up and down again.
First, let me tell you about the setup. There's a boolvalue inside the player which is set to the variable "Mobile". It defines if the player is on a mobile device or not. Camera, it's pretty obvious. game.Workspace.CurrentCamera Equipped is a Boolean variable which defines if the Tool is equipped or not. Neck is a variable that leads to the Motor6D known as Neck. It's inside the character's torso.
Here's my overly complicated snippet of code.
Let me divide it into to parts. This is the part that runs on computers:
if not Mobile.Value then
Camera.Changed:connect(function()
if (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude > 1 and Equipped then
Mouse.TargetFilter = nil
if not Proning then
Neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
Neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
elseif Proning then
Neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0) * CFrame.new(0, 0.5, 0) * CFrame.Angles(math.rad(-90), 0, 0)
Neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
end
elseif (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude < 1 and Equipped then
mouse.TargetFilter = workspace
Neck.C1 = CFrame.new()
if not Proning then
Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0)
elseif Proning then
Neck.C0 = CFrame.new(0, 1.5, 1) * CFrame.Angles((math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y)+math.rad(90)), 0, 0)
end
end
end)
This is the part that runs on mobile devices:
elseif Mobile.Value then
Camera.Changed:connect(function()
if (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude > 1 and Equipped then
Mouse.TargetFilter = nil
if not Proning then
Neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
Neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
elseif Proning then
Neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0) * CFrame.new(0, 0.5, 0) * CFrame.Angles(math.rad(-90), 0, 0)
Neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
end
elseif (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude < 1 and Equipped then
mouse.TargetFilter = workspace
Neck.C1 = CFrame.new()
if not Proning then
Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y)+math.rad(22.5), 0, 0)
elseif Proning then
Neck.C0 = CFrame.new(0, 1.5, 1) * CFrame.Angles((math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y)+math.rad(90-22.5)), 0, 0)
end
end
end)
end
Here is a video to show what happens
Could someone PLEASE tell me WHY THE HECK mobile is ruining this script?
I have an idea for a solution, and that is to move the mouse to a position so it'll set itself. Probably because I have this part in the script: game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter

3 comments
If you need to tap all over the screen, why not make a 'calibration' on spawn?
That's what I've been thinking, but I can't think of how to move the mouse using a script...
You could set camera to first person and change it back to center it. I think that's the limitation of changing mouse position