TheUnknownDiscord

player gravity control

Dec 3rd, 2021 (edited)
216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NLS([[
  2. local power = 1
  3. owner.Chatted:Connect(function(msg)
  4. if msg:sub(1,7) == "-power " then
  5. power = msg:sub(7,#msg)
  6. end
  7. end)
  8. local donthit = {}
  9. for i,v in pairs(owner.Character:GetDescendants()) do
  10. pcall(function()
  11. table.insert(donthit,v)
  12. end)
  13. end
  14. for i,v in pairs(workspace:GetDescendants()) do
  15. pcall(function()
  16. if v.CanCollide == false then
  17. table.insert(donthit,v)
  18. end
  19. end)
  20. end
  21. jump = false
  22. local Speed = 0
  23. speed2 = 16
  24. local rotspeed = 0
  25. local rotspeed2 = 0
  26. local mouse = owner:GetMouse()
  27. local uis = game:GetService("UserInputService")
  28. local animationTrack = owner.Character.Humanoid:LoadAnimation(owner.Character.Animate.walk.WalkAnim)
  29. animationTrack.Looped = true
  30. animationTrack.Priority = Enum.AnimationPriority.Movement
  31. local animationTrack3 = owner.Character.Humanoid:LoadAnimation(owner.Character.Animate.jump.JumpAnim)
  32. animationTrack3.Priority = Enum.AnimationPriority.Movement
  33. LastAttack = 0
  34. uis.InputBegan:Connect(function(input)
  35. input = input.KeyCode
  36. if input == Enum.KeyCode.W then
  37. Speed = 1
  38. animationTrack:Play()
  39. local Tick = game:GetService("RunService").Stepped:wait()
  40. if (Tick - LastAttack) < 1.5 then
  41. speed2 = 20
  42. else
  43. speed2 = 16
  44. end
  45. LastAttack = Tick
  46. for i,v in pairs(owner.Character:GetDescendants()) do
  47. pcall(function()
  48. if v.Name ~= "HumanoidRootPart" then
  49. local density = 0
  50. local friction = 0
  51. local elasticity = 0
  52. local frictionWeight = 100000000000
  53. local elasticityWeight = 0
  54. local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
  55. v.CustomPhysicalProperties = physProperties
  56. end
  57. end)
  58. end
  59. elseif input == Enum.KeyCode.A then
  60. rotspeed = 1
  61. rotspeed2 = 0
  62. elseif input == Enum.KeyCode.S then
  63. Speed = -1
  64. animationTrack:Play()
  65. for i,v in pairs(owner.Character:GetDescendants()) do
  66. pcall(function()
  67. if v.Name ~= "HumanoidRootPart" then
  68. local density = 0
  69. local friction = 0
  70. local elasticity = 0
  71. local frictionWeight = 100000000000
  72. local elasticityWeight = 0
  73. local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
  74. v.CustomPhysicalProperties = physProperties
  75. end
  76. end)
  77. end
  78. elseif input == Enum.KeyCode.D then
  79. rotspeed = -1
  80. rotspeed2 = 0
  81. elseif input == Enum.KeyCode.Space then
  82. animationTrack3:Play()
  83. jump = true
  84. wait(0.25)
  85. jump = false
  86. end
  87. end)
  88. uis.InputEnded:Connect(function(input)
  89. input = input.KeyCode
  90. if input == Enum.KeyCode.W then
  91. Speed = 0
  92. animationTrack:Stop()
  93. for i,v in pairs(owner.Character:GetDescendants()) do
  94. pcall(function()
  95. if v.Name ~= "HumanoidRootPart" then
  96. local density = 0
  97. local friction = 0
  98. local elasticity = 0
  99. local frictionWeight = 100000000000
  100. local elasticityWeight = 0
  101. local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
  102. v.CustomPhysicalProperties = physProperties
  103. end
  104. end)
  105. end
  106. elseif input == Enum.KeyCode.A then
  107. rotspeed =0
  108. rotspeed2 = 0
  109. elseif input == Enum.KeyCode.D then
  110. rotspeed =0
  111. rotspeed2 = 0
  112. elseif input == Enum.KeyCode.S then
  113. Speed = 0
  114. animationTrack:Stop()
  115. for i,v in pairs(owner.Character:GetDescendants()) do
  116. pcall(function()
  117. if v.Name ~= "HumanoidRootPart" then
  118. local density = 0
  119. local friction = 0
  120. local elasticity = 0
  121. local frictionWeight = 100000000000
  122. local elasticityWeight = 0
  123. local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
  124. v.CustomPhysicalProperties = physProperties
  125. end
  126. end)
  127. end
  128. end
  129. end)
  130. local jumpp = Instance.new("NumberValue")
  131. jumpp.Value = -15
  132. block = owner.Character.HumanoidRootPart
  133. local xzGyro = Instance.new("BodyGyro")
  134. xzGyro.MaxTorque = Vector3.new(100000,0,100000)
  135. xzGyro.P = 100000
  136. xzGyro.D = 2500
  137. xzGyro.Parent = owner.Character.HumanoidRootPart
  138. game:GetService("RunService").RenderStepped:Connect(function()
  139. block.Velocity = block.CFrame.LookVector * Speed * speed2
  140. block.AssemblyAngularVelocity = block.CFrame.UpVector * rotspeed * 5
  141. end)
  142. local bf = Instance.new("BodyForce", owner.Character.HumanoidRootPart)
  143. local bf2 = Instance.new("BodyVelocity", owner.Character.HumanoidRootPart)
  144. bf2.MaxForce = Vector3.new(0,750,0)
  145. bf2.Velocity = Vector3.new()
  146. pcall(function()
  147. game:GetService("RunService").RenderStepped:Connect(function()
  148. if jump then
  149. jumpp.Value = 15 * power
  150. bf.Force = block.CFrame.upVector * workspace.Gravity * block:GetMass() * jumpp.Value
  151. elseif not jump then
  152. local tweenService = game:GetService("TweenService")
  153. local timeToFade = .125
  154. local object = jumpp
  155. local tweenInfo = TweenInfo.new(timeToFade)
  156. local goal = {}
  157. goal.Value = -30 * power
  158. local tween = tweenService:Create(object, tweenInfo, goal)
  159. tween:Play()
  160. bf.Force = block.CFrame.upVector * workspace.Gravity * block:GetMass() * jumpp.Value
  161. end
  162. local params = RaycastParams.new()
  163. params.FilterDescendantsInstances = {block, owner.Character,donthit}
  164. params.FilterType = Enum.RaycastFilterType.Blacklist
  165. local result = workspace:Raycast(block.Position, block.CFrame.upVector * -10 + block.CFrame.lookVector * 5, params)
  166. local result2 = workspace:Raycast(block.Position, block.CFrame.upVector * 10 + block.CFrame.lookVector * 5, params)
  167. local result3 = workspace:Raycast(block.Position, block.CFrame.upVector * 10, params)
  168. local result4 = workspace:Raycast(block.Position, block.CFrame.upVector * -10 + block.CFrame.lookVector * -5, params)
  169. local result5 = workspace:Raycast(block.Position, block.CFrame.upVector * 10 + block.CFrame.lookVector * -5, params)
  170. local result6 = workspace:Raycast(block.Position, block.CFrame.upVector * -10, params)
  171.  
  172. if (result) then
  173. local currentRightVector = block.CFrame.RightVector
  174. local upVector = result.Normal
  175. local newFacialVector = currentRightVector:Cross(upVector)
  176. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  177. elseif (result2) then
  178. local currentRightVector = block.CFrame.RightVector
  179. local upVector = result2.Normal
  180. local newFacialVector = currentRightVector:Cross(upVector)
  181. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  182. elseif (result3) then
  183. local currentRightVector = block.CFrame.RightVector
  184. local upVector = result3.Normal
  185. local newFacialVector = currentRightVector:Cross(upVector)
  186. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  187. elseif (result4) then
  188. local currentRightVector = block.CFrame.RightVector
  189. local upVector = result4.Normal
  190. local newFacialVector = currentRightVector:Cross(upVector)
  191. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  192. elseif (result5) then
  193. local currentRightVector = block.CFrame.RightVector
  194. local upVector = result5.Normal
  195. local newFacialVector = currentRightVector:Cross(upVector)
  196. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  197. elseif (result6) then
  198. local currentRightVector = block.CFrame.RightVector
  199. local upVector = result6.Normal
  200. local newFacialVector = currentRightVector:Cross(upVector)
  201. xzGyro.CFrame = CFrame.fromMatrix(block.Position, currentRightVector, upVector, newFacialVector)
  202. end
  203.  
  204. end)
  205. end)
  206. owner.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
  207. ]], owner.PlayerGui)
RAW Paste Data Copied