hey so im making this dragging system for a game and its just super janky with how it functions. I have tried the drag constraints but they dont really work in a way thats applicable. The goal is to make it both smoother and also so it collides with other objects while being dragged. Heres the code and a video of what happens
Server:
game:GetService('ReplicatedStorage').MoveItem.OnServerEvent:Connect(function(plr, item, position)
item.Position = position
end)
Client:
local dragging = false
local plr = game:GetService('Players').LocalPlayer
local item = nil
game:GetService('RunService').Heartbeat:Connect(function()
local mouse = plr:GetMouse()
mouse.TargetFilter = plr.Character
if not item and mouse.Target and mouse.Target.Parent then
item = mouse.Target
elseif item and item.Parent and item:FindFirstChild('Draggable') and dragging == true then
if item:IsA('BasePart') then
if (item.Position - workspace.CurrentCamera.CFrame.Position).Magnitude > 20 then
local pos = workspace.CurrentCamera.CFrame.Position + workspace.CurrentCamera.CFrame.LookVector * 20
item.Position = pos
game:GetService('ReplicatedStorage').MoveItem:FireServer(item, pos)
else
local pos = workspace.CurrentCamera.CFrame.Position + workspace.CurrentCamera.CFrame.LookVector * 10
item.Position = pos
game:GetService('ReplicatedStorage').MoveItem:FireServer(item, pos)
end
end
elseif dragging == false then
item = nil
end
end)
plr:GetMouse().Button1Up:Connect(function()
dragging = false
end)
plr:GetMouse().Button1Down:Connect(function()
dragging = true
end)
Explorer:
Video:
https://youtu.be/WExFHENLPmc (if video isn’t there wait a minute for it to upload)