How to add collisions to ragdoll

how do i make characters parts collide when ragdolled (when not dead)

heres the script

function ragdoll.Start(character)
	local orgSpeed = character.Humanoid.WalkSpeed
	local orgJump = character.Humanoid.JumpPower
	if character.Ragdolled.Value then return end
	character.Ragdolled.Value = true
	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a0 = Instance.new("Attachment")
			local a1 = Instance.new("Attachment")
			a0.Parent = joint.Part0
			a1.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a0
			socket.Attachment1 = a1
			a0.CFrame = joint.C0
			a1.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true

			joint.Enabled = false 
		end
	end
	
	
	
	character.Humanoid.WalkSpeed = 0
	character.Humanoid.JumpPower = 0

	character.Humanoid.PlatformStand = true 

	character.Humanoid.AutoRotate = false
end

function ragdoll.Stop(character)
	local orgSpeed = character.Humanoid.WalkSpeed
	local orgJump = character.Humanoid.JumpPower
	local hrp = character:FindFirstChild("HumanoidRootPart")
	local hum = character:FindFirstChild("Humanoid")

	hum.PlatformStand = false

	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("BallSocketConstraint") then
			joint:Destroy()
		end

		if joint:IsA("Motor6D") then
			joint.Enabled = true
		end
	end

	character.Ragdolled.Value = false

	hum:ChangeState(Enum.HumanoidStateType.GettingUp)

	hum.WalkSpeed = orgSpeed
	hum.JumpPower = orgJump

	hum.AutoRotate = true
end

return ragdoll
1 Like

There are probably better methods out there, but the method I use is adding Parts and welding them to the character’s limbs with the same size and such. In my opinion, it’s kind of more controllable for me because I can resize them down a little if needed. Try doing parts.

i dont understand what you mean, explain more

Create a part with the same properties as a limb and Weld (connect) them together. Then destroy after unragdolling.

Honestly just set there CanCollide property to true. Its not that hard. And yes it will work.

Doesn’t work unless you probably put it in some runservice. Roblox’s systems just gonna set it back to false again.

1 Like

Nope. I have tried many times of doing it without runservice and it works fine.

1 Like

it doesnt work like that, roblox auto sets the collision to false

I dont think so it works for me. Dont know why not for you.

if it works for you, thats. a glitch. The humanoid is supposed to constantly set the collision of limbs to false.

The easiest method is definitly to weld some parts on the limbs.

you could just use Instance.new() to create some parts, do some stuff to make it smaller would be optimal, and then attach them to the hand or lower arm/leg (or you could attach it to all of em)

2 Likes

Actually its not. Humanoids only set collision to false of parts that are a part attached with a motor 6d and a ball socket is well not a motor 6d therefore humanoid won’t be consistently settings its collision to true.

1 Like

Strange, maybe my memory isn’t work, the last time I made ragdoll was nearly a year ago. But im preeetty sure I tried that and it didnt work

The method i use is setting the humanoidstatetype to Physics on the client whenever the player gets ragdolled. It should make limbs collide with stuff.

1 Like

i know its outdated but, its prob because you set it to collide before setting the ball socket constraint, just as he said, it only sets to false if there is a motor 6d, i tried to put the collision after it and it worked, but a bit glitchy

Interesting. I’ll have to check my code to see if that was the case lol.

When you ragdoll the player, set the player’s Collision Group to something else that doesn’t collide with anything, then loop through the player’s body parts and create a part in each one of them, welding them and turning the collision on.

Then you can create collision by using these functions.

local Character = Player.Character

local function SetCollision(CollisionGroup : string)
 for _, v in pairs(Character:GetChildren()) do
  if v:IsA("BasePart") then
   v.CollisionGroup = CollisionGroup
  end
 end
end

local function SetupHitbox(p : Part)
 local Hitbox = Instance.new("Part")
 Hitbox.Size = Vector3.new(2, 2, 2)
 Hitbox.Name = p.Name.." Hitbox"
 Hitbox.CanCollide = true
 Hitbox.Anchored = false

 local Weld = Instance.new("WeldConstraint")
 Weld.Part0 = p
 Weld.Part1 = Hitbox

 Hitbox.Parent = p
 Weld.Parent = Hitbox
end

local function DestroyHitboxes()
 for _, v in pairs(Character:GetChildren()) do
  if string.find(v.Name, "Hitbox") and v:IsA("Part") and v:FindFirstChildOfClass("WeldConstraint") then
   v:Destroy()
  end
 end
end

oops forgot to close this, i found solution shortly after by creating duplicates of the character’s limbs

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.