I’m creating a dash and it works perfectly fine, just not when you dash and jump right after or dash in the air. I’d like the dash to travel the same distance on ground or in air.
Glitched part: https://gyazo.com/24cf3b589374aaae78b5799ceb5fccb7
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local dashanim = script:WaitForChild("Animation")
local velocity = 14000
local debounce = false
local cooldown = 1.5
local duration = 0.3
local function Dash()
local character = player.Character
if character and not debounce then
debounce = true
local hum = character.Humanoid
local hrp = character.HumanoidRootPart
--local loadedanimation = hum.Animator:LoadAnimation(DashAnim)
local dashDirection = nil
local moveDirection = hum.MoveDirection
local lookVector = hrp.CFrame.LookVector
local minusVeclocity = -velocity
local isOnGround = hum.FloorMaterial ~= Enum.Material.Air and hum.FloorMaterial ~= Enum.Material.Water
if isOnGround then
if moveDirection == Vector3.new(0,0,0) then
dashDirection = hrp.Position + Vector3.new(lookVector.X, 0, lookVector.Z)
else
dashDirection = hrp.Position + Vector3.new(moveDirection.X, 0, moveDirection.Z)
end
local body = Instance.new("BodyGyro")
body.Parent = hrp
body.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
body.D = 0
body.P = 500000
body.CFrame = CFrame.lookAt(hrp.Position, dashDirection)
local attachment = Instance.new("Attachment")
attachment.Parent = hrp
local vectorForce = Instance.new("VectorForce")
vectorForce.Parent = hrp
vectorForce.Attachment0 = attachment
vectorForce.Force = Vector3.new(0,0,minusVeclocity)
--loadedanimation:Play()
hum.AutoRotate = false
wait(duration)
hum.AutoRotate = true
vectorForce:Destroy()
body:Destroy()
attachment:Destroy()
wait(duration * 2)
--loadedanimation:Stop()
end
wait(cooldown)
debounce = false
end
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
Dash()
end
end)