Currently, I am working on a game with a dash feature. This feature currently uses BodyVelocity to push a character forward, left, right, or backwards depending on the wasd key pressed. The main issue I have is that for some reason or another, the character has less velocity when dashing on the ground, or when they have certain tools equipped. I would like the dash to be more streamlined, so they always go the same distance whether they are dashing in the air or on the ground. Is there any way to make this code better?
Here is the code I am currently using:
dashremote.OnServerEvent:Connect(function(player, dir)
if not canDash then return end
local stagger = char:FindFirstChild("Humanoid"):FindFirstChild("Stagger").Value
if isKnocked.Value == false then
canDash = false
local char = player.Character
local root = char:FindFirstChild("HumanoidRootPart")
local MaxStagger = 300 + (player:WaitForChild("Data"):FindFirstChild("Endurance").Value * 3)
if char.Humanoid:FindFirstChild("RacePowder") == nil then
char:FindFirstChild("Humanoid"):FindFirstChild("Stagger").Value -= 10
end
local StaggerBar = player.PlayerGui.GUI.StaggerBar.Stagger
local staggerGUI = StaggerBar.Parent.Label
local StaggerHP = StaggerBar.StaggerLabel
staggerGUI.Text = char:FindFirstChild("Humanoid"):FindFirstChild("Stagger").Value .. ' / ' .. MaxStagger
StaggerHP.Text = staggerGUI.Text
StaggerBar:TweenSize(UDim2.new(char:FindFirstChild("Humanoid"):FindFirstChild("Stagger").Value / MaxStagger, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.05, true)
player:WaitForChild("Data"):WaitForChild("Athletics XP").Value += 60
local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(10000,0,10000)
bv.Velocity = (char.Torso.CFrame* CFrame.Angles(0, math.rad(dir), 0)).lookVector * 90
game.Debris:AddItem(bv, dashDuration)
local anim = script.DashForward
if dir == 180 then
anim = script.DashBackward
elseif dir == 90 then
anim = script.DashLeft
elseif dir == -90 then
anim = script.DashRight
end
local playanim = char.Humanoid:LoadAnimation(anim)
playanim:Play()
wait(dashDuration)
playanim:Stop()
wait(dashCooldown - dashDuration)
canDash = true
end
end)