Advertisement
SxScripting

Advanced Dash System

May 20th, 2023
23,382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. local Character = script.Parent;
  2. local Humanoid = Character:WaitForChild("Humanoid");
  3. local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
  4.  
  5. local SideGyro = Instance.new("BodyGyro")
  6. SideGyro.MaxTorque = Vector3.new(3e5,0,3e5)
  7. SideGyro.P = 5e5
  8. SideGyro.Parent = HumanoidRootPart
  9.  
  10. local RunService = game:GetService('RunService')
  11. local UserInputService = game:GetService('UserInputService')
  12.  
  13. local Dashing = false
  14. local DashSpeed = 45
  15. local DoubleTaps = {}
  16.  
  17. local Animations = {
  18. ["DashRight"] = 'rbxassetid://12878249954';
  19. ["DashLeft"] = 'rbxassetid://12878251537';
  20. ["DashFront"] = 'rbxassetid://12878253087';
  21. ["DashBack"] = 'rbxassetid://12878254845';
  22. }
  23.  
  24. for i,v in pairs(Animations) do
  25. local Anim = Instance.new("Animation")
  26. Anim.AnimationId = v
  27. Anim = Humanoid:LoadAnimation(Anim)
  28. Animations[i] = Anim
  29. end
  30.  
  31. function Dash(Key)
  32. if Dashing then
  33. return
  34. end
  35.  
  36. local DashAnim = "Back"
  37. local Front = -1
  38. local Side = 0
  39.  
  40. if Key == Enum.KeyCode.A then
  41. Side=-1
  42. Front = 0
  43. DashAnim = "Left"
  44. end
  45.  
  46. if Key == Enum.KeyCode.D then
  47. Side=1
  48. Front = 0
  49. DashAnim = "Right"
  50. end
  51.  
  52. if Key == Enum.KeyCode.W then
  53. Side=0
  54. Front = 1
  55. DashAnim = "Front"
  56. end
  57.  
  58. if Key == Enum.KeyCode.S then
  59. Side=0
  60. Front = -1
  61. DashAnim = "Back"
  62. end
  63.  
  64. Dashing = true
  65. Animations["Dash"..DashAnim]:Play()
  66.  
  67. local DashVelocity = Instance.new("BodyVelocity")
  68. DashVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
  69. DashVelocity.P = 9e9
  70. DashVelocity.Parent = HumanoidRootPart
  71. DashVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * (Front * DashSpeed) + HumanoidRootPart.CFrame.RightVector * (Side * DashSpeed)
  72.  
  73. coroutine.wrap(function()
  74. task.wait(.1)
  75. local DashEffect = game.ReplicatedStorage.DustTrail:Clone();
  76. DashEffect.Parent = workspace;
  77.  
  78. if DashAnim == "Left" then
  79. DashEffect.DustRight:Destroy();
  80. DashEffect.CFrame = Character["Right Leg"].CFrame * CFrame.new(-1,0,-2);
  81. else if DashAnim == "Right" then
  82. DashEffect.DustLeft:Destroy();
  83. DashEffect.CFrame = Character["Left Leg"].CFrame * CFrame.new(3,2,5);
  84. else if DashAnim == "Front" then
  85. DashEffect.DustLeft:Destroy();
  86. DashEffect.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,-1,3);
  87. else
  88. DashEffect.DustLeft:Destroy();
  89. DashEffect.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,-1,-.5);
  90. end
  91. end
  92. end
  93.  
  94. for i,v in pairs(DashEffect:GetDescendants()) do
  95. if not v:IsA("ParticleEmitter") then continue end
  96. v:Emit(5);
  97. end
  98.  
  99. game.Debris:AddItem(DashEffect, .5);
  100. end)()
  101.  
  102.  
  103. repeat wait() DashVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * (Front * DashSpeed) + HumanoidRootPart.CFrame.RightVector * (Side * DashSpeed)
  104. until not Animations["Dash"..DashAnim].IsPlaying
  105. Dashing = false
  106. DashVelocity:Destroy()
  107. end
  108.  
  109. function LoadDoubleTap(Key,Funct)
  110. DoubleTaps[Key] = tick()-10
  111. UserInputService.InputBegan:Connect(function(Pressed,Typing)
  112.  
  113. if Pressed.KeyCode == Key then
  114. if (tick() - DoubleTaps[Key]) < .23 then
  115. Funct(Key)
  116. else
  117. DoubleTaps[Key] = tick()
  118. end
  119. end
  120.  
  121. end)
  122. end
  123.  
  124. LoadDoubleTap(Enum.KeyCode.W,Dash)
  125. LoadDoubleTap(Enum.KeyCode.A,Dash)
  126. LoadDoubleTap(Enum.KeyCode.S,Dash)
  127. LoadDoubleTap(Enum.KeyCode.D,Dash)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement