Advertisement
InfinateSpectre

Untitled

Apr 18th, 2021
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. -- Services
  2. local get = function(x) return game:GetService(x) end
  3. local players = get('Players')
  4. local ws = get('Workspace')
  5. local rs = get('ReplicatedStorage')
  6. local rus = get('RunService')
  7. local uis = get('UserInputService')
  8. local coregui = get('CoreGui')
  9. local http = get('HttpService')
  10. local ts = get('TeleportService')
  11.  
  12. -- Shorthand
  13. local plr = players.LocalPlayer
  14. local char = (plr and (plr.Character or plr.CharacterAdded:Wait()) or nil)
  15. local hrp = plr and (char:WaitForChild('HumanoidRootPart')) or nil
  16. local hum = plr and (char:WaitForChild('Humanoid')) or nil if plr then plr.CharacterAdded:Connect(function(c)char=c hrp=c:WaitForChild'HumanoidRootPart'hum=c:WaitForChild('Humanoid')end)end
  17. local cf = CFrame
  18. local v3 = Vector3
  19. local ud2 = UDim2
  20. local c3 = Color3
  21. local rgb = c3.fromRGB
  22. local step = rus.Stepped
  23. local rstep = rus.RenderStepped
  24. local heartbeat = rus.Heartbeat
  25.  
  26. -- Functions
  27.  
  28. local function bindToStep(callback,doDebounce,debounceWait)
  29. local debounce = false
  30. step:Connect(function()
  31. if not debounce then
  32. debounce = doDebounce ~= nil
  33. callback()
  34. if debounceWait and doDebounce then
  35. wait(debounceWait)
  36. end
  37. debounce = false
  38. end
  39. end)
  40. end
  41.  
  42. local function bindToRenderStep(callback,doDebounce,debounceWait)
  43. local debounce = false
  44. rstep:Connect(function()
  45. if not debounce then
  46. debounce = doDebounce ~= nil
  47. callback()
  48. if debounceWait and doDebounce then
  49. wait(debounceWait)
  50. end
  51. debounce = false
  52. end
  53. end)
  54. end
  55.  
  56. local function bindToHeartbeat(callback,doDebounce,debounceWait)
  57. local debounce = false
  58. heartbeat:Connect(function()
  59. if not debounce then
  60. debounce = doDebounce ~= nil
  61. callback()
  62. if debounceWait and doDebounce then
  63. wait(debounceWait)
  64. end
  65. debounce = false
  66. end
  67. end)
  68. end
  69.  
  70. local JSON = {
  71. stringify = function(...) return http:JSONEncode(...) end;
  72. parse = function(...) return http:JSONDecode(...) end;
  73. }
  74.  
  75.  
  76.  
  77. ------------------------------------------------------------------------------------------------------------------
  78.  
  79.  
  80.  
  81. -- Module --
  82.  
  83. local module = {}
  84.  
  85. -- Configure Constraints --
  86.  
  87. function module.configureAlignment(part0,part1,useBodyPosition) -- configures the two parts so that they are ready to be aligned. After this is done, you can set the position and orientation of the "part1_attAP" attachment, which is the attachment inside of part1
  88.  
  89. local function create(c,part0)
  90. local obj = Instance.new(c)
  91. for i,v in pairs(part0) do
  92. obj[i] = v
  93. end
  94. return obj
  95. end
  96.  
  97. local part0_attP = create('Attachment',{
  98. Parent = part0;
  99. })
  100.  
  101. local part1_attP = create('Attachment',{
  102. Parent = part1;
  103. })
  104.  
  105. local part0_attO = create('Attachment',{
  106. Parent = part0;
  107. })
  108.  
  109. local part1_attO = create('Attachment',{
  110. Parent = part1;
  111. })
  112.  
  113. local ap = create('AlignPosition',{
  114. Name = 'LFbodyf';
  115. Parent = part0;
  116. ApplyAtCenterOfMass = true;
  117. MaxForce = 67752;
  118. MaxVelocity = math.huge/9e110;
  119. ReactionForceEnabled = false;
  120. Responsiveness = 200;
  121. RigidityEnabled = false;
  122. Attachment0 = part0_attP;
  123. Attachment1 = part1_attP;
  124. })
  125.  
  126. local ao = create('AlignOrientation',{
  127. Name = 'LFbodyf';
  128. Parent = part0;
  129. MaxAngularVelocity = math.huge/9e110;
  130. MaxTorque = 67752;
  131. PrimaryAxisOnly = false;
  132. ReactionTorqueEnabled = false;
  133. Responsiveness = 200;
  134. RigidityEnabled = false;
  135. Attachment0 = part0_attO;
  136. Attachment1 = part1_attO;
  137. })
  138.  
  139. --[[ delay(1,function()
  140. ap.RigidityEnabled = true
  141. ao.RigidityEnabled = true
  142. end) ]]
  143.  
  144. local data = {
  145. info = {
  146. alignPos = ap;
  147. alignOri = ao;
  148. attachments = {
  149. part0 = {
  150. pos = part0_attP;
  151. ori = part0_attO;
  152. };
  153. part1 = {
  154. pos = part1_attP;
  155. ori = part1_attO;
  156. };
  157. }
  158. };
  159. }
  160. function data.setpos(pos)
  161. part1_attP.Position = pos
  162. end
  163. function data.setori(ori)
  164. part1_attO.Orientation = ori
  165. end
  166.  
  167. if useBodyPosition then
  168. local bp = Instance.new('BodyPosition',part0)
  169. bp.Name = 'FFmover'
  170. --[[ bp.MaxForce = v3.new(9e9,9e9,9e9)
  171. bp.P = 100
  172. bp.D = 100 ]]
  173. bindToStep(function()
  174. if bp then
  175. bp.Position = part1_attP.Position
  176. end
  177. end)
  178. end
  179.  
  180. return data
  181.  
  182. end
  183.  
  184. -- Return the module --
  185. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement