Do you struggle with ragdolls? Do you need a new way of making ragdolls? Are you looking for a good ragdoll module? You should try this module out!
Introducing, Inverse Kinematics Ragdoll Module! This module uses my method of making IK Ragdolls. It’s the 2023 way of making ragdolls, It has better collisions and it’s less buggier than the previous method (BallSocketConstraint Method)
Module Link
IK Ragdoll Module (DevXylo Method)
Module Guide:
Step 1 - Requiring the module.
You will need to require the module in order to use the functions.
local ragdollModule = require(game:GetService("ServerStorage"):WaitForChild("DevXylo's IK Ragdoll Method"))
Step 2 - Ragdolling the rig/player.
Now you’re simply going to call the function :IKRagdoll()
and put in the rig/character in order to make it ragdoll.
local request = ragdollModule:IKRagdoll(game:WaitForChild("Players"):GetPlayers()[1].Character) -- This line is going to return a table full of parts, attachments and values, while ragdolling the rig/character.
local returnedTable
returnedTable = request -- The important table for Unragdolling.
Step 2 - Unragdolling/Rebuilding
Now you’re going to use the returnedTable variable to unragdoll/rebuild the rig/character.
ragdollModule:Rebuild(game:WaitForChild("Players"):GetPlayers()[1].Character, returnedTable)
Full Module Script:
local physService = game:GetService("PhysicsService")
physService:RegisterCollisionGroup("IgnoreHitbox")
physService:CollisionGroupSetCollidable("IgnoreHitbox", "IgnoreHitbox", false)
physService:CollisionGroupSetCollidable("IgnoreHitbox", "Default", false)
local ragdollCollisionGroup = "IgnoreHitbox"
local limbList = {
"Head",
"UpperTorso",
"LowerTorso",
"LeftFoot",
"LeftLowerLeg",
"LeftUpperLeg",
"RightFoot",
"RightLowerLeg",
"RightUpperLeg",
"LeftHand",
"LeftLowerArm",
"LeftUpperArm",
"RightHand",
"RightLowerArm",
"RightUpperArm",
"HumanoidRootPart"
}
local module = {}
local instances = {}
local function CollisionGroup(c)
local storedLimbCollisionGroups = {
["Head"] = "",
["UpperTorso"] = "",
["LowerTorso"] = "",
["LeftFoot"] = "",
["LeftLowerLeg"] = "",
["LeftUpperLeg"] = "",
["RightFoot"] = "",
["RightLowerLeg"] = "",
["RightUpperLeg"] = "",
["LeftHand"] = "",
["LeftLowerArm"] = "",
["LeftUpperArm"] = "",
["RightHand"] = "",
["RightLowerArm"] = "",
["RightUpperArm"] = "",
["HumanoidRootPart"] = ""
}
for _, limbName in pairs(limbList) do
local limb = c:FindFirstChild(limbName)
if limb then
storedLimbCollisionGroups[limbName] = limb.CollisionGroup
limb.CollisionGroup = ragdollCollisionGroup
end
end
return storedLimbCollisionGroups
end
local function CreateHitbox(c)
local hitbox = Instance.new("Model", c)
for _, limbName in pairs(limbList) do
local limb = c:FindFirstChild(limbName)
if limb then
local limbHitbox = Instance.new("Part", hitbox)
limbHitbox.Name = limb.Name
limbHitbox.CanCollide = true
limbHitbox.Size = limb.Size
limbHitbox.Transparency = 1
local hitboxWeld = Instance.new("WeldConstraint", limbHitbox)
limbHitbox.CFrame = limb.CFrame
hitboxWeld.Part0 = limb
hitboxWeld.Part1 = limbHitbox
end
end
return hitbox
end
function CheckObjects(c)
local humanoid = c:WaitForChild("Humanoid")
local primaryPart = c.PrimaryPart
local liveRagdollTargetRefs = c:WaitForChild("Humanoid"):FindFirstChild("LiveRagdollTargetRefs")
local IKParts = workspace:FindFirstChild("IKParts")
if liveRagdollTargetRefs == nil then
liveRagdollTargetRefs = Instance.new("Folder")
liveRagdollTargetRefs.Parent = c:WaitForChild("Humanoid")
liveRagdollTargetRefs.Name = "LiveRagdollTargetRefs"
end
if IKParts == nil then
IKParts = Instance.new("Folder")
IKParts.Parent = workspace
IKParts.Name = "IKParts"
end
end
function Velocity(c, hitbox)
local players = game:GetService("Players")
local humanoid = c:WaitForChild("Humanoid")
local primaryPart = hitbox:WaitForChild(c.PrimaryPart.Name)
local debris = game:GetService("Debris")
humanoid.PlatformStand = true
local velocityAttachment = Instance.new("Attachment", primaryPart)
local velocity = Instance.new("AngularVelocity", velocityAttachment)
velocity.Attachment0 = velocityAttachment
velocity.MaxTorque = 1500
velocity.AngularVelocity = primaryPart.CFrame.RightVector * 50
velocity.RelativeTo = Enum.ActuatorRelativeTo.World
velocity.ReactionTorqueEnabled = true
debris:AddItem(velocityAttachment, 0.2)
end
function CreateRopeTarget(name, ikstart, ikend, joint, c)
local humanoid = c:WaitForChild("Humanoid")
local part = Instance.new("Part")
part.Transparency = 1
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.CFrame = ikend.CFrame
part.Name = name
part.Parent = workspace:WaitForChild("IKParts")
local at = Instance.new("Attachment")
at.Parent = part
at.Visible = false
local r = Instance.new("RopeConstraint")
r.Length = 6
r.Visible = false
r.Attachment0 = joint
r.Attachment1 = at
r.Parent = part
r.Visible = false
local ik = Instance.new("IKControl")
ik.Name = name
ik.Type = Enum.IKControlType.Position
ik.ChainRoot = ikstart
ik.EndEffector = ikend
ik.Target = part
ik.Parent = humanoid
local ob = Instance.new("ObjectValue")
ob.Name = name
ob.Value = part
ob.Parent = humanoid:WaitForChild("LiveRagdollTargetRefs")
table.insert(instances, part)
table.insert(instances, at)
table.insert(instances, r)
table.insert(instances, ik)
table.insert(instances, ob)
return part
end
function module:IKRagdoll(c : Model)
CheckObjects(c)
instances = {}
local humanoid = c:WaitForChild("Humanoid")
local primaryPart = c.PrimaryPart
local walkSpeed = nil
local jumpPower = nil
local storedCollisionGroups = CollisionGroup(c)
local hitbox = CreateHitbox(c)
primaryPart.Massless = true
if humanoid.RigType == Enum.HumanoidRigType.R15 then
c:WaitForChild("LowerTorso"):WaitForChild("Root").Enabled = false
elseif humanoid.RigType == Enum.HumanoidRigType.R6 then
c:WaitForChild("HumanoidRootPart"):WaitForChild("RootJoint").Enabled = false
end
table.insert(instances, hitbox)
walkSpeed = humanoid.WalkSpeed
jumpPower = humanoid.JumpPower
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
if humanoid.Health > 0 then
humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
coroutine.wrap(Velocity)(c, hitbox)
CreateRopeTarget(c.Name .. "_RagIKTarget_RH", c.RightUpperArm, c.RightHand, c.UpperTorso.RightShoulderRigAttachment, c)
CreateRopeTarget(c.Name .. "_RagIKTarget_LH", c.LeftUpperArm, c.LeftHand, c.UpperTorso.LeftShoulderRigAttachment, c)
CreateRopeTarget(c.Name .. "_RagIKTarget_RF", c.RightUpperLeg, c.RightFoot, c.LowerTorso.RightHipRigAttachment, c)
CreateRopeTarget(c.Name .. "_RagIKTarget_LF", c.LeftUpperLeg, c.LeftFoot, c.LowerTorso.LeftHipRigAttachment, c)
return {instances, walkSpeed, jumpPower, storedCollisionGroups}
end
function module:Rebuild(c : Model, restoredTable : "table")
local players = game:GetService("Players")
local humanoid = c:WaitForChild("Humanoid")
local primaryPart = c.PrimaryPart
local instancesTable = restoredTable[1]
local savedWalkSpeed = restoredTable[2]
local savedJumpPower = restoredTable[3]
local restoredCollisionGroupTable = restoredTable[4]
for _, instance in pairs(instancesTable) do
instance:Destroy()
end
for limbName, collisionName in pairs(restoredCollisionGroupTable) do
local limb = c:FindFirstChild(limbName)
if limb then
limb.CollisionGroup = collisionName
end
end
humanoid.PlatformStand = false
primaryPart.Anchored = true
primaryPart.CFrame = CFrame.new(primaryPart.Position) * CFrame.new(0, c:GetExtentsSize().Y / 2, 0) * CFrame.Angles(0, math.rad(90), 0)
primaryPart.Anchored = false
primaryPart.Massless = false
if humanoid.RigType == Enum.HumanoidRigType.R15 then
c:WaitForChild("LowerTorso"):WaitForChild("Root").Enabled = true
elseif humanoid.RigType == Enum.HumanoidRigType.R6 then
c:WaitForChild("HumanoidRootPart"):WaitForChild("RootJoint").Enabled = true
end
humanoid.WalkSpeed = savedWalkSpeed
humanoid.JumpPower = savedJumpPower
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
return module
This Module is BETA so feedback is always appreciated
Best regards, DevXylo.
Q/A:
Q1: Can you animate the ragdoll?
A1: I actually saw a topic where a Developer asked if you could animate the ragdoll. The answer is yes. The ragdoll edits the position of every limbs using Inverse Kinematics, so you can still animate the ragdoll.
Q2: Are there any bugs/glitches?
A2: Yes, there can be physics glitches and bugs, so don’t expect the module to be glitch-free.