Gametoy

Untitled

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