awzp

Animation (not by me)

May 31st, 2018
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. game.Players.LocalPlayer.CameraMode = "Classic"
  2.  
  3. local s = game.Players.LocalPlayer.Character local Torso = s:WaitForChild("Torso")
  4. local CF, V3, Ang, pi, sqrt = CFrame.new, Vector3.new, CFrame.Angles, math.pi, math.sqrt
  5. s.Humanoid.WalkSpeed = 8
  6. local Body = s.HumanoidRootPart
  7. local Head = s.Head
  8. local TorsoWeld = Body.RootJoint
  9. local HeadWeld = s.Torso.Neck
  10. local Mouse = game.Players.LocalPlayer:GetMouse()
  11. local Camera = game.Workspace.CurrentCamera
  12. local c = true
  13. local Crouch = 0
  14. local Crouching = false
  15. local SprintAmount = 0
  16. local Sprinting = false
  17. local Lean = 0
  18. local Humanoid = s.Humanoid
  19. function minmax(l, x, u)
  20. return math.max(l, math.min(x, u))
  21. end
  22. function MakeWeld(Part0, Part1)
  23. local w = Instance.new("Weld", Part0)
  24. w.Part0, w.Part1 = Part0, Part1
  25. return w
  26. end
  27. function JointAction(Weld, AttachPoint, Point)
  28. local Part0Down = Weld.Part0.CFrame * AttachPoint * Ang(-pi/2, 0, 0)
  29. local ApplicDist = math.min(2, (Point - Part0Down.p).magnitude)
  30. local JointCFrame = Part0Down * CF(V3(), Part0Down:inverse() * Point)
  31. local JointLine = Weld.Part0.CFrame:inverse() * JointCFrame * Ang(pi/2, 0, 0)
  32. Weld.C0 = JointLine * CF(0, -ApplicDist / 2, -sqrt(1 - ApplicDist^2 / 4))
  33. Weld.C1 = Ang(math.acos(ApplicDist / 2), 0, 0)
  34. end
  35. function Smooth(Start, End, x)
  36. return (3*x^2-2*x^3)*(End - Start) + Start
  37. end
  38. Body.CanCollide = false
  39. TorsoWeld.C1 = CF(0, -1, 0)
  40. HeadWeld.C1 = CF(0, -0.5, 0)
  41. function KeyPressed(Key)
  42. if Key == "c" then
  43. if not Crouching then
  44. Sprinting = false
  45. Crouching = true
  46. local WalkSpeedStart = Humanoid.WalkSpeed
  47. local CrouchStart = Crouch
  48. local SprintAmountStart = SprintAmount
  49. for i = 0, 1, 1/10 do
  50. wait(1/30)
  51. Crouch = Smooth(CrouchStart, -1, i)
  52. SprintAmount = Smooth(SprintAmountStart, 0, i)
  53. Humanoid.WalkSpeed = Smooth(WalkSpeedStart, 4, i)
  54. end
  55. else
  56. Sprinting = false
  57. Crouching = false
  58. local WalkSpeedStart = Humanoid.WalkSpeed
  59. local CrouchStart = Crouch
  60. local SprintAmountStart = SprintAmount
  61. for i = 0, 1, 1/10 do
  62. wait(1/30)
  63. Crouch = Smooth(CrouchStart, 0, i)
  64. SprintAmount = Smooth(SprintAmountStart, 0, i)
  65. Humanoid.WalkSpeed = Smooth(WalkSpeedStart, 8, i)
  66. end
  67. end
  68. elseif Key == "0" then
  69. Sprinting = true
  70. Crouching = false
  71. local WalkSpeedStart = Humanoid.WalkSpeed
  72. local CrouchStart = Crouch
  73. local SprintAmountStart = SprintAmount
  74. for i = 0, 1, 1/15 do
  75. wait(1/30)
  76. Crouch = Smooth(CrouchStart, 0, i)
  77. SprintAmount = Smooth(SprintAmountStart, 1, i)
  78. Humanoid.WalkSpeed = Smooth(WalkSpeedStart, 22, i)
  79. end
  80. elseif Key == "q" then
  81. local Start = Lean
  82. for i = 0, 1, 1/10 do
  83. wait(1/30)
  84. Lean = Smooth(Start, 1, i)
  85. end
  86. elseif Key == "e" then
  87. local Start = Lean
  88. for i = 0, 1, 1/10 do
  89. wait(1/30)
  90. Lean = Smooth(Start, -1, i)
  91. end
  92. elseif Key == "p" then
  93. c = not c
  94. if c then
  95. game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
  96. else
  97. game.Players.LocalPlayer.CameraMode = "Classic"
  98. end
  99. end
  100. end
  101. function KeyDepressed(Key)
  102. if Key == "0" then
  103. Sprinting = false
  104. local WalkSpeedStart = Humanoid.WalkSpeed
  105. local SprintAmountStart = SprintAmount
  106. for i = 0, 1, 1/15 do
  107. wait(1/30)
  108. SprintAmount = Smooth(SprintAmountStart, 0, i)
  109. Humanoid.WalkSpeed = Smooth(WalkSpeedStart, 8, i)
  110. end
  111. elseif Key == "q" or Key == "e" then
  112. local Start = Lean
  113. for i = 0, 1, 1/10 do
  114. wait(1/30)
  115. Lean = Smooth(Start, 0, i)
  116. end
  117. end
  118. end
  119. Mouse.KeyDown:connect(KeyPressed)
  120. Mouse.KeyUp:connect(KeyDepressed)
  121. local LegWeld1, LegWeld2 = MakeWeld(Body, s["Right Leg"]), MakeWeld(Body, s["Left Leg"])
  122. local i = 0
  123. local SmoothVelocity, Raise = Vector3.new(1, 1, 1), 0
  124. local Sprint = 1
  125. while wait(1/30) do
  126. if not Humanoid.PlatformStand and not Humanoid.Sit then
  127. LegWeld1.Parent = Body
  128. LegWeld2.Parent = Body
  129. if Body.Velocity.magnitude >= 1 then SmoothVelocity = (SmoothVelocity * 3 + Body.Velocity) / 4 Raise = Raise * 7/8 + 1/8 Sprint = (Body.Velocity.magnitude / 8 + 0.0001)^(3/4) else Raise = Raise * 7/8 end
  130. local ti = (Body.CFrame - Body.CFrame.p):inverse()
  131. i = i + ((ti * Torso.Velocity) * V3(1, 0, 1)).magnitude/60/Sprint
  132. JointAction(LegWeld1, CF(0.5, Crouch * 2/3 - 1, 0), (Body.CFrame * CF(0.5, Sprint * math.min(math.max(-0.1, Raise * math.cos(pi*i) / 3), 1/4) - 2.9, 0) + SmoothVelocity.unit * Sprint * math.sin(pi*i)).p)
  133. JointAction(LegWeld2, CF(-0.5, Crouch * 2/3 - 1, 0), (Body.CFrame * CF(-0.5, Sprint * math.min(math.max(-0.1, Raise * -math.cos(pi*i) / 3), 1/4) - 2.9, 0) + SmoothVelocity.unit * Sprint * -math.sin(pi*i)).p)
  134. TorsoWeld.C0 = CF(0, Crouch - 1, 0) * Ang(Crouch*pi/8 + SprintAmount*pi*(ti*SmoothVelocity).unit.z/8, (Crouch - SprintAmount)*math.cos(pi*i)*pi / 16, -SprintAmount*pi*(ti*SmoothVelocity).unit.x/8 + Lean*pi/8)
  135. HeadWeld.C0 = CF(0, 1, 0) * Ang(-Crouch*pi/8 - SprintAmount*pi*(ti*SmoothVelocity).unit.z/8, (SprintAmount - Crouch)*math.cos(pi*i)*pi / 16, SprintAmount*pi*(ti*SmoothVelocity).unit.x/8 + Lean*pi/8)
  136. if (Camera.CoordinateFrame.p - Head.CFrame.p).magnitude <= 3 then
  137. CameraLV = (Body.CFrame:inverse() * Camera.CoordinateFrame).lookVector
  138. Parse = (CameraLV + Vector3.new(0, 0, -1)).unit
  139. Parsex, Parsey, Parsez = CF(V3(), Parse):toEulerAnglesXYZ()
  140. TorsoWeld.C0 = TorsoWeld.C0 * Ang(minmax(-pi/6, Parsex, pi/6) / (1 + SprintAmount), minmax(-pi/6, Parsey, pi/6) / (1 + SprintAmount), 0)
  141. HeadWeld.C0 = HeadWeld.C0 * Ang(minmax(-pi/3, Parsex, pi/3) / (1 + SprintAmount), minmax(-pi/3, Parsey, pi/3) / (1 + SprintAmount), 0)
  142. -- TorsoWeld.C0 = TorsoWeld.C0 * Ang(Parsex, Parsey, 0)
  143. -- HeadWeld.C0 = HeadWeld.C0 * Ang(Parsex, Parsey, 0)
  144. end
  145. else
  146. TorsoWeld.C0 = CF(0, -1, 0)
  147. HeadWeld.C0 = CF(0, 1, 0)
  148. LegWeld1.Parent = nil
  149. LegWeld2.Parent = nil
  150. end
  151. end
Add Comment
Please, Sign In to add comment