You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I would like to make a system similar to that of the item pickup system from gmod. Allowing for the picking up of items to rotate, move, and distance them.
What is the issue?
I’m not sure how to start making such a system, as the drag detector’s given modes don’t really have the functionality I’m looking for.
If anyone could give me tips or pointers as to make such a system, please tell me, it would be greatly appreciated.
This is taken straight from my game if you still need it. Currently only works with BaseParts but it does its job. Pass any object through for it to receive a GMod-esque DragDetector. I used a Tag system (hence the onInstanceAdded). GLHF.
local function onInstanceAdded(Object)
local Drag = Instance.new("DragDetector")
Drag.MaxActivationDistance = 24
Drag.Responsiveness = 50
Drag.MaxForce = math.huge
Drag.MaxTorque = math.huge
Drag.DragStyle = Enum.DragDetectorDragStyle.Scriptable
Drag.ResponseStyle = Enum.DragDetectorResponseStyle.Physical
Drag.ApplyAtCenterOfMass = true
Drag:SetAttribute("Player","")
Drag.DragStart:Connect(function(player)
Drag:SetAttribute("Player",player.Name)
Drag.ReferenceInstance = player.Character.HumanoidRootPart
CachedReference = player.Character
end)
Drag.DragEnd:Connect(function()
Drag:SetAttribute("Player","")
Drag.ReferenceInstance = nil
end)
if Object:IsA("BasePart") then
Drag.DragContinue:Connect(function(player)
if (Object.Position - player.Character.HumanoidRootPart.Position).Magnitude > Drag.MaxActivationDistance*4/3 then Drag.Enabled = false Drag.Enabled = true end
end)
Drag.RightMouseClick:Connect(function(player)
if player.Name == Drag:GetAttribute("Player",player.Name) then
Object.Anchored = not Object.Anchored
end
end)
end
local function GModStyle(cursorRay : Ray)
-- Exclude dragged object from raycast detection
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Drag.Parent,CachedReference}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local distance = 0
local hitPoint = Vector3.zero
local hitNormal = Vector3.yAxis
local raycastResult = workspace:Raycast(cursorRay.Origin, cursorRay.Direction, raycastParams)
if raycastResult then
distance = math.clamp((cursorRay.Origin-raycastResult.Position).Magnitude-0.5,0.5,Drag.MaxActivationDistance*2/3)
else
distance = Drag.MaxActivationDistance*2/3
end
return CFrame.new(cursorRay.Origin+(cursorRay.Unit.Direction*distance))
end
Drag:SetDragStyleFunction(GModStyle)
Drag.Parent = Object
end