howdy roblox devs! i’ve made a (extremely) messy ragdoll dragging script which is functional but very, very far from perfect. here’s what i mean:
as you can see the movement is very weird and just doesn’t feel smooth at all. does anyone have suggestions how to improve it? should i add animations? thanks!
client side code:
dragEvent.OnClientEvent:Connect(function(char)
for i,v in pairs(char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
v.CanCollide = true
end
end
local torso = char:WaitForChild("Torso")
local pChar = player.Character
local pRootPart = pChar:WaitForChild("HumanoidRootPart")
local pTorso = pChar:WaitForChild("Torso")
local pRightArm = pChar:WaitForChild("Right Arm")
local pLeftArm = pChar:WaitForChild("Left Arm")
local pRightGrip : Attachment = pRightArm:WaitForChild("RightGripAttachment")
local pLeftGrip : Attachment = pLeftArm:WaitForChild("LeftGripAttachment")
local npcRightGrip : Attachment = char:WaitForChild("Right Arm"):WaitForChild("RightGripAttachment")
local npcLeftGrip : Attachment = char:WaitForChild("Left Arm"):WaitForChild("LeftGripAttachment")
local rightDragSocket = Instance.new("BallSocketConstraint")
local leftDragSocket = Instance.new("BallSocketConstraint")
local rightShoulder : Motor6D = pTorso:FindFirstChild("Right Shoulder")
local leftShoulder : Motor6D = pTorso:FindFirstChild("Left Shoulder")
rightShoulder.Enabled = false
leftShoulder.Enabled = false
rightDragSocket.Parent = pRightArm
leftDragSocket.Parent = pLeftArm
local closeGrip : Attachment
if (npcRightGrip.WorldPosition - (pRightGrip.WorldPosition + pLeftGrip.Position)).Magnitude < (npcLeftGrip.WorldPosition - (pRightGrip.WorldPosition + pLeftGrip.Position)).Magnitude then
closeGrip = npcRightGrip
else
closeGrip = npcLeftGrip
end
rightDragSocket.Parent = pRightArm
leftDragSocket.Parent = pLeftArm
rightDragSocket.Attachment0 = pRightGrip
rightDragSocket.Attachment1 = closeGrip
leftDragSocket.Attachment0 = pLeftGrip
leftDragSocket.Attachment1 = closeGrip
local rightArmTorsoLink = Instance.new("Attachment")
local leftArmTorsoLink = Instance.new("Attachment")
local rightArmLink = Instance.new("Attachment")
local leftArmLink = Instance.new("Attachment")
rightArmTorsoLink.Parent = pTorso
leftArmTorsoLink.Parent = pTorso
rightArmLink.Parent = pRightArm
leftArmLink.Parent = pLeftArm
rightArmTorsoLink.CFrame = CFrame.new(1.3, 0.25, -1, 1, 0, 0, 0, 1, 0, 0, 0, 1)
rightArmLink.CFrame = CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
leftArmTorsoLink.CFrame = CFrame.new(-1.3, 0.25, -1, -1, 0, 0, 0, -1, 0, 0, 0, 1)
leftArmLink.CFrame = CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)
local rightArmSocket = Instance.new("BallSocketConstraint")
local leftArmSocket = Instance.new("BallSocketConstraint")
rightArmSocket.Parent = pRightArm
leftArmSocket.Parent = pLeftArm
rightArmSocket.Attachment0 = rightArmTorsoLink
rightArmSocket.Attachment1 = rightArmLink
leftArmSocket.Attachment0 = leftArmTorsoLink
leftArmSocket.Attachment1 = leftArmLink
rightDragSocket.LimitsEnabled = true
leftDragSocket.LimitsEnabled = true
for i,v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
-- v.CanCollide = true
end
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
rightDragSocket:Destroy()
leftDragSocket:Destroy()
rightArmTorsoLink:Destroy()
leftArmTorsoLink:Destroy()
rightArmLink:Destroy()
leftArmLink:Destroy()
rightArmSocket:Destroy()
leftArmSocket:Destroy()
rightShoulder.Enabled = true
leftShoulder.Enabled = true
char:FindFirstChild("HumanoidRootPart"):FindFirstChild("ProximityPrompt").Enabled = true
end
end)
end)