Advertisement
Animescapetower

RAGDOLL

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