Im currently making a drag system using DragDetectors for a game. I currently have it working properly on a pc using a custom DragsStyle:
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local PickupRemote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("OnPickup")
local detector = script.Parent
local part = detector.Parent
local CARRY_DISTANCE = 7
local dragOffset = Vector3.zero
local relativeRotation = CFrame.identity
detector.DragStart:Connect(function(_, _, _, hitFrame, clickedPart)
if clickedPart:IsDescendantOf(part) then
local partCFrame = part:GetPivot()
local cameraRotation = camera.CFrame.Rotation
relativeRotation = partCFrame.Rotation
dragOffset = partCFrame:PointToObjectSpace(hitFrame.Position)
PickupRemote:FireServer(part, true)
end
end)
detector.DragEnd:Connect(function()
PickupRemote:FireServer(part, false)
end)
detector:SetDragStyleFunction(function()
local rayOrigin = camera.CFrame.Position
local rayDirection = camera.CFrame.LookVector * CARRY_DISTANCE
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = { part, player.Character }
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local size = part:GetExtentsSize()
local rotation = part:GetPivot().Rotation
local hit = workspace:Blockcast(
CFrame.new(rayOrigin) * rotation,
size,
rayDirection,
raycastParams
)
local distance = hit and (hit.Distance + 0.2) or CARRY_DISTANCE
local targetPosition = rayOrigin + rayDirection.Unit * distance
return CFrame.new(targetPosition) * relativeRotation * CFrame.new(-dragOffset)
end)
It also works on mobile but the problem is that the user needs to hold their finger in order to not let go of the object, making it hard to turn around and move while dragging. How do i make it so that the DragDetector stays active even if i let go of the tap and end the drag when a button is pressed?