Advertisement
AlbertsHere

r6 ragdoll 2

Feb 18th, 2019
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. wait(1)
  2.  
  3. local character = game.Players.LocalPlayer.Character
  4.  
  5. function recurse(root,callback,i)
  6. i= i or 0
  7. for _,v in pairs(root:GetChildren()) do
  8. i = i + 1
  9. callback(i,v)
  10.  
  11. if #v:GetChildren() > 0 then
  12. i = recurse(v,callback,i)
  13. end
  14. end
  15.  
  16. return i
  17. end
  18.  
  19. function ragdollJoint(part0, part1, attachmentName, className, properties)
  20. attachmentName = attachmentName.."RigAttachment"
  21. local constraint = Instance.new(className.."Constraint")
  22. constraint.Attachment0 = part0:FindFirstChild(attachmentName)
  23. constraint.Attachment1 = part1:FindFirstChild(attachmentName)
  24. constraint.Name = "RagdollConstraint"..part1.Name
  25.  
  26. for _,propertyData in next,properties or {} do
  27. constraint[propertyData[1]] = propertyData[2]
  28. end
  29.  
  30. constraint.Parent = character
  31. end
  32.  
  33. function getAttachment0(attachmentName)
  34. for _,child in next,character:GetChildren() do
  35. local attachment = child:FindFirstChild(attachmentName)
  36. if attachment then
  37. return attachment
  38. end
  39. end
  40. end
  41.  
  42. character:WaitForChild("Humanoid").Died:connect(function()
  43. local camera = workspace.CurrentCamera
  44. if camera.CameraSubject == character.Humanoid then--If developer isn't controlling camera
  45. camera.CameraSubject = character.UpperTorso
  46. end
  47.  
  48. --Make it so ragdoll can't collide with invisible HRP, but don't let HRP fall through map and be destroyed in process
  49. character.HumanoidRootPart.Anchored = true
  50. character.HumanoidRootPart.CanCollide = false
  51.  
  52. --Helps to fix constraint spasms
  53. recurse(character, function(_,v)
  54. if v:IsA("Attachment") then
  55. v.Axis = Vector3.new(0, 1, 0)
  56. v.SecondaryAxis = Vector3.new(0, 0, 1)
  57. v.Rotation = Vector3.new(0, 0, 0)
  58. end
  59. end)
  60.  
  61. --Re-attach hats
  62. for _,child in next,character:GetChildren() do
  63. if child:IsA("Accoutrement") then
  64. --Loop through all parts instead of only checking for one to be forwards-compatible in the event
  65. --ROBLOX implements multi-part accessories
  66. for _,part in next,child:GetChildren() do
  67. if part:IsA("BasePart") then
  68. local attachment1 = part:FindFirstChildOfClass("Attachment")
  69. local attachment0 = getAttachment0(attachment1.Name)
  70. if attachment0 and attachment1 then
  71. --Shouldn't use constraints for this, but have to because of a ROBLOX idiosyncrasy where
  72. --joints connecting a character are perpetually deleted while the character is dead
  73. local constraint = Instance.new("HingeConstraint")
  74. constraint.Attachment0 = attachment0
  75. constraint.Attachment1 = attachment1
  76. constraint.LimitsEnabled = true
  77. constraint.UpperAngle = 0 --Simulate weld by making it difficult for constraint to move
  78. constraint.LowerAngle = 0
  79. constraint.Parent = character
  80. end
  81. end
  82. end
  83. end
  84. end
  85.  
  86. ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist", "BallSocket", {
  87. {"LimitsEnabled",true};
  88. {"UpperAngle",5};
  89. })
  90. ragdollJoint(character.UpperTorso, character.Head, "Neck", "BallSocket", {
  91. {"LimitsEnabled",true};
  92. {"UpperAngle",15};
  93. })
  94.  
  95. local handProperties = {
  96. {"LimitsEnabled", true};
  97. {"UpperAngle",0};
  98. {"LowerAngle",0};
  99. }
  100. ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist", "Hinge", handProperties)
  101. ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist", "Hinge", handProperties)
  102.  
  103. local shinProperties = {
  104. {"LimitsEnabled", true};
  105. {"UpperAngle", 0};
  106. {"LowerAngle", -75};
  107. }
  108. ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
  109. ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
  110.  
  111. local footProperties = {
  112. {"LimitsEnabled", true};
  113. {"UpperAngle", 15};
  114. {"LowerAngle", -45};
  115. }
  116. ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle", "Hinge", footProperties)
  117. ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle", "Hinge", footProperties)
  118.  
  119. --TODO fix ability for socket to turn backwards whenn ConeConstraints are shipped
  120. ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder", "BallSocket")
  121. ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow", "BallSocket")
  122. ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder", "BallSocket")
  123. ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow", "BallSocket")
  124. ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip", "BallSocket")
  125. ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip", "BallSocket")
  126. end)
Advertisement
RAW Paste Data Copied
Advertisement