Hi guys,
So I made a Dash script, here is the entire thing:
Summary
local Cam = workspace.CurrentCamera
local Tapped = false
local DoubleTapTime = 0.2
local CoolDown = 1.5
local LastTime = tick()
local LastTime2 = tick()
local LastTime3 = tick()
local LastTime4 = tick()
local DB = false
--FORWARD DASH
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.W then
local now = tick()
local difference = (now - LastTime)
if difference <= DoubleTapTime and not DB then
DB = true
HRP.Velocity = Cam.CFrame.lookVector * 200
wait(CoolDown)
DB = false
end
LastTime = tick()
elseif UIS:IsKeyDown(Enum.KeyCode.W) and input.KeyCode == Enum.KeyCode.X then
if not DB then
DB = true
HRP.Velocity = Cam.CFrame.lookVector * 200
wait(CoolDown)
DB = false
end
end
end)
--BACKWARD DASH
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.S then
local now = tick()
local difference = (now - LastTime2)
if difference <= DoubleTapTime and not DB then
DB = true
HRP.Velocity = Cam.CFrame.lookVector * -200
wait(CoolDown)
DB = false
end
LastTime2 = tick()
elseif UIS:IsKeyDown(Enum.KeyCode.S) and input.KeyCode == Enum.KeyCode.X then
if not DB then
DB = true
HRP.Velocity = Cam.CFrame.lookVector * -200
wait(CoolDown)
DB = false
end
end
end)
--LEFT DASH
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.A then
local now = tick()
local difference = (now - LastTime3)
if difference <= DoubleTapTime and not DB then
DB = true
HRP.Velocity = Cam.CFrame.rightVector * -200
wait(CoolDown)
DB = false
end
LastTime3 = tick()
elseif UIS:IsKeyDown(Enum.KeyCode.A) and input.KeyCode == Enum.KeyCode.X then
if not DB then
DB = true
HRP.Velocity = Cam.CFrame.rightVector * -200
wait(CoolDown)
DB = false
end
end
end)
--RIGHT DASH
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.D then
local now = tick()
local difference = (now - LastTime4)
if difference <= DoubleTapTime and not DB then
DB = true
HRP.Velocity = Cam.CFrame.rightVector * 200
wait(CoolDown)
DB = false
end
LastTime4 = tick()
elseif UIS:IsKeyDown(Enum.KeyCode.D) and input.KeyCode == Enum.KeyCode.X then
DB = true
HRP.Velocity = Cam.CFrame.rightVector * 200
wait(CoolDown)
DB = false
end
end)
Basically the code increases the Velocity of the player and uses Camera.CFrame.Vector
do decide the direction, based on the Key the player pressed.
It all works great but since I am using Camera.Cframe
, the player can sometimes dash up into the air. This would be fine if it was the same strength as the dash is on the ground, but for some reason it seems to be twice as strong or even greater.
Here is a gif of dashing on the ground:
https://gyazo.com/315b7a436d3b37a28464fb8685516c8a
Here is a gif of dashing into the air:
https://gyazo.com/c520ef1fab933c680b6b78f8a511fac4
As you can see from the two gifs, when the dash is used when the camera is looking up or down, the dash seems to be way stronger when compared to the usual dash.