Trying to achieve a ragdoll effect similar to Grand Piece Online’s
However, when the ragdoll is activated on an NPC, they don’t fall over at all, even though all their limbs are numb. How can I make sure the NPC / player falls over when they ragdoll? Here is the logic that controls the ragdoll:
-- This function runs for all players and npcs
function module.BuildRag(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
humanoid.Died:Once(function()
DoRagdoll(character, true)
end)
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
rootPart.CanCollide = false
end
task.spawn(function()
if players:GetPlayerFromCharacter(character) ~= nil then
return -- we dont want it to set network for player, as we dont know how that will effect things. should be done by server already
end
pcall(function()
for _, bp in character:GetDescendants() do
if bp:IsA("BasePart") then
if bp.Anchored then continue end
bp:SetNetworkOwner(nil)
end
end
end)
end)
local attachmentMap = buildAttachmentMap(character)
local ragdollConstraints = buildConstraints(attachmentMap)
local collisionFilters = buildCollisionFilters(attachmentMap, character.PrimaryPart)
collisionFilters.Parent = ragdollConstraints
ragdollConstraints.Parent = character
end
-- This controls the ragdoll
function setRagdollEnabled(humanoid, isEnabled)
local ragdollConstraints = humanoid.Parent:FindFirstChild("RagdollConstraints")
for _, constraint in pairs(ragdollConstraints:GetChildren()) do
if constraint:IsA("Constraint") then
local rigidJoint = constraint.RigidJoint.Value
local expectedValue = (not isEnabled) and constraint.Attachment1.Parent or nil
if rigidJoint.Part1 ~= expectedValue then
rigidJoint.Part1 = expectedValue
end
end
end
end
function DoRagdoll(character, bool)
assert(character:IsA("Model"))
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local state = if bool then Enum.HumanoidStateType.Physics else Enum.HumanoidStateType.GettingUp
humanoid:ChangeState(state)
setRagdollEnabled(humanoid, bool)
end
Heres what my ragdoll looks like:
I had it working a while ago, but it no longer works. Heres what it used to look like
I’ve also tried this solution, where you set PlatformStand to true rather than changing humanoid state type. Doesn’t work however and achieves the same effect