Advertisement
Guest User

R15 script

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