I am making a ragdoll module which I will be using for future projects and theres a small problem…
Right now it’s doing some sort of yoga pose and I want it to be more realistic; how would I achieve this?
Code:
local physicsService = game:GetService("PhysicsService")
local collider = script:WaitForChild("RagdollCollision")
local module = {}
physicsService:CreateCollisionGroup("Ragdoll")
physicsService:CollisionGroupSetCollidable("Ragdoll", "Ragdoll", false)
function module:Ragdoll(character, bool)
if character == nil or bool == nil then return end
if bool == true and character:FindFirstChild("Humanoid") then
local limbs = {}
local human = character:FindFirstChild("Humanoid")
human.RequiresNeck = false
for _,v in pairs(character:GetChildren()) do
human:ChangeState(Enum.HumanoidStateType.Ragdoll)
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
physicsService:SetPartCollisionGroup(v, "Ragdoll")
table.insert(limbs, v)
end
end
local ragdollCollidersModel = Instance.new("Model", character)
ragdollCollidersModel.Name = "Colliders"
for _,v in ipairs(limbs) do
local colliderClone = collider:Clone()
colliderClone.Anchored = false
physicsService:SetPartCollisionGroup(colliderClone, "Ragdoll")
colliderClone.Parent = ragdollCollidersModel
local weld = Instance.new("Weld", v)
weld.Part0 = v
weld.Part1 = colliderClone
end
for _,v in ipairs(character:GetDescendants()) do
if v:IsA("Motor6D") then
if v.Part0 == nil or v.Part1 == nil then return end
local ballSocket = Instance.new("BallSocketConstraint")
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = v.C0
a1.CFrame = v.C1
a0.Parent = v.Part0
a1.Parent = v.Part1
ballSocket.Attachment0 = a0
ballSocket.Attachment1 = a1
ballSocket.Parent = a0.Parent
v.Part0 = nil
end
end
human.PlatformStand = true
character.HumanoidRootPart.CanCollide = false
human:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
end
return module
function module:Ragdoll(character, bool)
if character == nil or bool == nil then return end
if bool == true and character:FindFirstChild("Humanoid") then
local limbs = {}
local human = character:FindFirstChild("Humanoid")
human.RequiresNeck = false
for _,v in pairs(character:GetChildren()) do
human:ChangeState(Enum.HumanoidStateType.Ragdoll)
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
physicsService:SetPartCollisionGroup(v, "Ragdoll")
table.insert(limbs, v)
end
end
local ragdollCollidersModel = Instance.new("Model", character)
ragdollCollidersModel.Name = "Colliders"
for _,v in ipairs(limbs) do
local colliderClone = collider:Clone()
colliderClone.Anchored = false
physicsService:SetPartCollisionGroup(colliderClone, "Ragdoll")
colliderClone.Parent = ragdollCollidersModel
local weld = Instance.new("Weld", v)
weld.Part0 = v
weld.Part1 = colliderClone
end
for _,v in ipairs(character:GetDescendants()) do
if v:IsA("Motor6D") then
if v.Part0 == nil or v.Part1 == nil then return end
local ballSocket = Instance.new("BallSocketConstraint")
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = v.C0
a1.CFrame = v.C1*CFrame.new(Vector3.new(10,0,0))
a0.Parent = v.Part0
a1.Parent = v.Part1
ballSocket.Attachment0 = a0
ballSocket.Attachment1 = a1
ballSocket.Parent = a0.Parent
v.Part0 = nil
end
end
human.PlatformStand = true
character.HumanoidRootPart.CanCollide = false
human:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
end