Hello! I am using a dash script but the dash only goes straight and you cannot change direction until the dash is finished. I want the dash to curve but I have no idea how to.
Help would be appreciated!
Heres my script:
local Character = script.Parent
local Player = game.Players.LocalPlayer
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local PlayerGui = Player.PlayerGui
local RunService = game:GetService('RunService')
local ContextActionService = game:GetService('ContextActionService')
local UserInput = game:GetService("UserInputService")
local Dashing = false
local DashSpeed = 80
local Cooldown = false
local CooldownTime = 0.9 -- Cooldown time (matches dashcooldown script)
local DashDuration = 0.25 -- Dash duration
local Animations = {
["DashRight"] = 'rbxassetid://18732415956',
["DashLeft"] = 'rbxassetid://18732414549',
["DashFront"] = 'rbxassetid://18732412700',
["DashBack"] = 'rbxassetid://18732406193',
}
for i, v in pairs(Animations) do
local Anim = Instance.new("Animation")
Anim.AnimationId = v
Animations[i] = Humanoid:LoadAnimation(Anim)
end
local DashSound = Instance.new("Sound")
DashSound.SoundId = 'rbxassetid://8653395088'
DashSound.Parent = HumanoidRootPart
-- GUI elements for cooldown UI
local player = game.Players.LocalPlayer
local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("DashCoolDownFrame")
local cooldownFrame = screenGui:WaitForChild("Framecool")
-- Function to update the cooldown UI
local function updateCooldownUI()
local currentTime = tick()
local elapsed = 0
cooldownFrame.Visible = true
while elapsed < CooldownTime do
elapsed = tick() - currentTime
local newWidth = 0.253 * (1 - (elapsed / CooldownTime)) -- Decrease width based on cooldown
cooldownFrame.Size = UDim2.new(newWidth, 0, 0.037, 0) -- Maintain the height of 0.037
RunService.Heartbeat:Wait()
end
cooldownFrame.Size = UDim2.new(0.253, 0, 0.037, 0) -- Reset size
cooldownFrame.Visible = false
end
local function Dash()
if Dashing or Cooldown then return end
local moveDirection = Humanoid.MoveDirection
local DashAnim = "Front"
if moveDirection.Magnitude == 0 then
moveDirection = HumanoidRootPart.CFrame.LookVector
else
if math.abs(moveDirection.X) > math.abs(moveDirection.Z) then
if moveDirection.X > 0 then
DashAnim = "Right"
else
DashAnim = "Left"
end
else
if moveDirection.Z > 0 then
DashAnim = "Front"
else
DashAnim = "Back"
end
end
end
Dashing = true
Cooldown = true
Animations["Dash" .. DashAnim]:Play()
-- Play the dash sound
DashSound:Play()
-- Apply dash velocity
local DashVelocity = Instance.new("BodyVelocity")
DashVelocity.MaxForce = Vector3.new(550000, 550000, 550000)
DashVelocity.P = 9e9
DashVelocity.Parent = HumanoidRootPart
DashVelocity.Velocity = moveDirection * DashSpeed
-- Dash visual effects
coroutine.wrap(function()
local DashEffect = game.ReplicatedStorage:WaitForChild("DustTrail"):Clone()
DashEffect.Parent = workspace
DashEffect.CFrame = Character.HumanoidRootPart.CFrame
for _, v in pairs(DashEffect:GetDescendants()) do
if v:IsA("ParticleEmitter") then
v:Emit(5)
end
end
game.Debris:AddItem(DashEffect, 0.5)
end)()
-- Wait for dash duration
task.wait(DashDuration)
DashVelocity:Destroy()
Dashing = false
-- Start the cooldown and update the UI
task.delay(CooldownTime, function()
Cooldown = false
end)
coroutine.wrap(updateCooldownUI)() -- Trigger cooldown UI update
end
-- Bind dash action to key or button
local function onAction(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
Dash()
end
end
ContextActionService:BindAction("DashAction", onAction, false, Enum.KeyCode.Q)
if UserInput.TouchEnabled then
local MobileButtons = PlayerGui:WaitForChild("MobileButtons")
MobileButtons.Enabled = true
MobileButtons.MobileFrame.DashButton.MouseButton1Down:Connect(function()
Dash()
end)
end