THIS IS FIRE!!! So much smoother than mine
I adjusted your function so that it can be used as one function instead of four different ones, the main difference is, however, that I changed the variables. Also, added a direction variable
For starters, control changed to dashStartSpeed for clarity, ev changed to dashEndSpeed, also for more clarity and increment changed completely to dashDuration (increment is converted to time)
I also used a similar method to compact it all into one function, hopefully this time I wrote it more clearly.
Changed its name too because now its just a general dash function
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character
local HRP = Character.PrimaryPart
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local DebrisService = game:GetService("Debris")
local gameSettings = UserSettings().GameSettings
local UIS = game.UserInputService
local Camera = workspace.Camera
local function dashFunction(direction, dashStartSpeed, dashDuration, dashEndSpeed)
local increment = ((dashEndSpeed- dashStartSpeed) / (dashDuration* 60)) * 2 -- Simple velocity calculation
local BodyVelocity = Instance.new("BodyVelocity", HRP)
BodyVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
gameSettings.RotationType = Enum.RotationType.CameraRelative --Makes player follow mouse)
local directionalForce
if direction == "forward" or direction == "right" then
directionalForce = 1 -- Imagine that the player position is a graph/2d coordinate, if all values => 0 then its either going up or left
elseif direction == "backward" or direction == "left" then
directionalForce = -1 -- And if its all =< 0 then its either going down or left (this works because the dash only changes X or Y value, not both at once)
end
for i=dashStartSpeed,dashEndSpeed,increment do
if direction == "forward" or direction == "backward" then
local MoveDirection = HRP.CFrame.LookVector
if Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.FallingDown then
BodyVelocity.Velocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) / 1.25 -- So that you dash less further in air
wait()
else
BodyVelocity.Velocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce)
wait()
end
elseif direction == "left" or direction == "right" then
local MoveDirection = HRP.CFrame.RightVector
if Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.FallingDown then
BodyVelocity.Velocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) / 1.25 -- So that you dash less further in air
wait()
else
BodyVelocity.Velocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce)
wait()
end
end
end
BodyVelocity:Destroy()
gameSettings.RotationType = Enum.RotationType.MovementRelative
end
--test and instructions
--Adjust variables beforehand, this test simulates W being held
local dashDirection
local dashStartSpeed = 55
local dashDuration = 0.35
local dashEndSpeed = 16
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
-- if WKey == true then
dashDirection = "forward"
dashFunction("forward", dashStartSpeed, dashDuration, dashEndSpeed)
end
end)
I also decided to not put the cooldown in the script because im too tired for that, its like 3 AM.
Anyways, this script works so well now that I understand it, thank you so much!
PS: If you dont want the dash speed to gradually lower, just change the dashEndSpeed to dashStartSpeed - 1
(this also works if you want your dash to start slow and get faster, if you want it to start slow, get fast and then get slow again then you could probably easily do it by just playing around with the function)
PS #2: If all the players have the same dash, consider defining the variables before the function so that its easier to read, in other words
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
-- if WKey == true then
dashDirection = "forward"
dashFunction()
end
end)
-- Looks way better IMO