You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m trying to add mobile support for my drag script. For PC players I use the mouse location for the part position and for mobile I want to use the players current camera look vector. When the player rotates their screen on a mobile device, I want the part to mimic the players look vector. I’ve been researching and trying different solutions for days and still can’t figure it out so now I’m here.
What is the issue? Include screenshots / videos if possible!
this is the line of code that I’m having issues with. It follows the characters head CFrame but it doesn’t account for the Y axis so when the player looks down the part doesn’t go down with it.
Here is the full drag code for context
function beginDrag (part)
ismoving = true
local Center = Instance.new("Attachment")
Center.Parent = part
Center.Name = "AttatchFixer"
local AlignOrient = Instance.new("AlignOrientation")
AlignOrient.Name = "OrientationFixer"
AlignOrient.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrient.Attachment0 = Center
AlignOrient.RigidityEnabled = true
AlignOrient.Parent = part
part.CanCollide = true
movepart = runservice.RenderStepped:Connect(function()
local getmouse = uis:GetMouseLocation()
local viewportcam = currentCam:ViewportPointToRay(getmouse.X, getmouse.Y)
if uis.MouseEnabled then
part.Position = player.Character:FindFirstChild("Head").Position + (viewportcam.Direction * 8)
AlignOrient.CFrame = player.Character:FindFirstChild("Head").CFrame
elseif uis.TouchEnabled then
part.CFrame = player.Character:FindFirstChild("Head").CFrame + (player.Character:FindFirstChild("Head").CFrame.LookVector * 6)
AlignOrient.CFrame = player.Character:FindFirstChild("Head").CFrame
end
end)
end
From my understanding of your issue, you’re trying to obtain the angle of the player’s screen that they’re looking through, the camera’s angle. In your code, you’re obtaining the CFrame of the Head of their character, but that’s not actually what the player uses to look around. Instead, in a local script, you can obtain the angle of the player’s Camera.
--local script
local cam = workspace.CurrentCamera
local function getCameraAngle()
return cam.CFrame.LookVector
end
I’m not sure if this is what you’re asking for, but it does seem like it.