Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local player = Players.LocalPlayer
- local char = player.Character or player.CharacterAdded:Wait()
- local humanoid = char:WaitForChild("Humanoid")
- local rootPart = char:WaitForChild("HumanoidRootPart")
- local keybind = require(game.ReplicatedStorage.CoolModules.Keybind)
- local dirteffect = char["Left Leg"].LeftFootAttachment:WaitForChild("DirtEffect")
- local FrontDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Forward)
- local LeftDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Left)
- local RightDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Right)
- local BackDash = char.Humanoid:FindFirstChild("Animator"):LoadAnimation(script.Animations.Dash.Back)
- local dashConfig = {
- speed = 90,
- cdtime = 2.5,
- duration = 0.3,
- maxforce = Vector3.new(1, 0, 1) * 300000,
- minvelocity = 0.2
- }
- local dashState = {
- canDash = true,
- isDashing = false,
- dashStartTime = 0
- }
- local action = keybind.GetAction("Fight", "Dash")
- action.KeyboardBinding.KeyCode = Enum.KeyCode.Q
- action.GamepadBinding.KeyCode = Enum.KeyCode.ButtonX
- action.KeyboardBinding.UIButton = player.PlayerGui.MobileButtons.Frame.DashButton
- keybind.EnableContext("Fight")
- local dashCDIcon = player.PlayerGui.Cooldowns.Frame.Dash
- local function getDashDirection()
- local moveDirection = humanoid.MoveDirection
- if moveDirection.Magnitude == 0 then
- moveDirection = rootPart.CFrame.LookVector
- end
- local relativeDirection = rootPart.CFrame:VectorToObjectSpace(moveDirection)
- local forwardDot = relativeDirection.Z
- local rightDot = relativeDirection.X
- local threshold = 0.5
- if forwardDot > threshold then
- return BackDash
- elseif forwardDot < -threshold then
- return FrontDash
- elseif rightDot > threshold then
- return RightDash
- elseif rightDot < -threshold then
- return LeftDash
- else
- return FrontDash
- end
- end
- local function Dash()
- if not dashState.canDash then return end
- script.SFX.dash:Play()
- dashCDIcon.BackgroundTransparency = 0.7
- dashCDIcon.ImageTransparency = 0.7
- dashCDIcon.UIStroke.Transparency = 0.7
- if humanoid.FloorMaterial ~= Enum.Material.Air then
- local rayOrigin = rootPart.Position
- local rayDirection = Vector3.new(0, -5, 0)
- local raycastParams = RaycastParams.new()
- raycastParams.FilterDescendantsInstances = {player.Character}
- raycastParams.FilterType = Enum.RaycastFilterType.Exclude
- local result = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
- if result and result.Instance then
- local partColor = result.Instance.Color
- local grayishColor = Color3.fromHex("#a19691")
- local startColor = grayishColor:Lerp(partColor, 0.7)
- local endColor = grayishColor:Lerp(partColor, 0.7)
- dirteffect.Color = ColorSequence.new{
- ColorSequenceKeypoint.new(0, startColor),
- ColorSequenceKeypoint.new(0.674, partColor),
- ColorSequenceKeypoint.new(1, endColor)
- }
- end
- dirteffect.Enabled = true
- end
- local currentanim :AnimationTrack
- dashState.canDash = false
- dashState.isDashing = true
- dashState.dashStartTime = os.clock()
- currentanim = getDashDirection()
- local direction
- if humanoid.MoveDirection.Magnitude > 0 then
- direction = humanoid.MoveDirection.Unit
- else
- direction = rootPart.CFrame.LookVector
- end
- local relativeDirection = char.HumanoidRootPart.CFrame:VectorToObjectSpace(char.Humanoid.MoveDirection)
- currentanim:Play(0.05)
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.MaxForce = dashConfig.maxforce
- bodyVelocity.Velocity = direction * dashConfig.speed * 5
- bodyVelocity.Parent = rootPart
- local dashConnection
- local reductionFactor = 1
- dashConnection = RunService.Heartbeat:Connect(function()
- local elapsed = os.clock() - dashState.dashStartTime
- if humanoid.MoveDirection.Magnitude > 0 then
- direction = humanoid.MoveDirection.Unit
- else
- direction = rootPart.CFrame.LookVector
- end
- if elapsed < dashConfig.duration and
- rootPart.AssemblyLinearVelocity.Magnitude > dashConfig.speed * dashConfig.minvelocity then
- bodyVelocity.Velocity = direction * dashConfig.speed * reductionFactor
- reductionFactor -= 0.05
- else
- dashState.isDashing = false
- bodyVelocity:Destroy()
- dashConnection:Disconnect()
- task.wait(0.1)
- dirteffect.Enabled = false
- end
- end)
- task.delay(dashConfig.cdtime + dashConfig.duration, function()
- dashState.canDash = true
- if bodyVelocity then bodyVelocity:Destroy() end
- dashCDIcon.BackgroundTransparency = 0.4
- dashCDIcon.ImageTransparency = 0.4
- dashCDIcon.UIStroke.Transparency = 0.4
- end)
- end
- action.Pressed:Connect(function()
- if dashState.canDash then
- task.spawn(Dash)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement