As you can see @HavocOmega the script of @Avallachi can change the direction whenever we want:
But I want make it so that when player press the Dash key it will take some seconds to let the Humanoid change his direction, then it could look like this:
As you saw in the video above it took a bit of seconds untill the player could change his direction. I think it took 0.5 seconds.
Here again the script of him:
local Camera = workspace.CurrentCamera
local Character = script.Parent
local Root = Character.HumanoidRootPart
local Humanoid = Character.Humanoid
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local _DashCooldown = 0.5
local _DashDistance = 30
local _DashDuration = 0.25
local _DashSpeed = _DashDistance / _DashDuration
local LastDash = 0
local LastMDirection = Vector3.new()
--// Utilities
function EaseQuarticIn(a, b, t, d)
local c = b - a
t /= d
return c * t * t * t * t + a
end
function Lerp(a, b, t) -- Linear interpolation (if you prefer this)
return a + (b - a) * t
end
--// Functions
function OnRenderStepped()
-- Set character orientation
local _, CameraYOrientation, _ = Camera.CFrame:ToOrientation()
Root.CFrame = CFrame.new(Root.Position) * CFrame.fromOrientation(0, CameraYOrientation, 0)
-- Calculate speed
local DashSpeed = EaseQuarticIn(_DashSpeed, 0, math.min(tick() - LastDash, _DashDuration), _DashDuration) -- Decelerate towards 0 speed
-- Apply velocity
local MoveDirection = Humanoid.MoveDirection == Vector3.new() and LastMDirection or Humanoid.MoveDirection
LastMDirection = MoveDirection
local DashVelocity = MoveDirection * DashSpeed
local Velocity = Root.AssemblyLinearVelocity
Root.AssemblyLinearVelocity = DashSpeed > 0 and Vector3.new(DashVelocity.X, Velocity.Y, DashVelocity.Z) or Velocity
end
function Dash()
local t = tick()
if t - LastDash >= _DashCooldown and Humanoid.MoveDirection ~= Vector3.new() then -- Won't dash if standing still
LastDash = t
end
end
function OnInputBegan(Input, Processed)
if Processed then return end
if Input.KeyCode == Enum.KeyCode.LeftShift then
Dash()
end
end
--// Events
RunService.RenderStepped:Connect(OnRenderStepped)
UserInputService.InputBegan:Connect(OnInputBegan)
The script is now overall really confusing. Could you show me the solution. I have been scripting since 10 months and I really dont know how I could make a extend the time of dash
Sorry, Iâm not following with what your saying. You could change the _DashDuration variable to 0.5 and also set the Humanoid walkspeed to 0 for _DashDuration.
local Camera = workspace.CurrentCamera
local Character = script.Parent
local Root = Character.HumanoidRootPart
local Humanoid = Character.Humanoid
local WalkSpeed = Humanoid.WalkSpeed
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local _DashCooldown = 0.5
local _DashDistance = 30
local _DashDuration = 0.5
local _DashSpeed = _DashDistance / _DashDuration
local LastDash = 0
local LastMDirection = Vector3.new()
--// Utilities
local function EaseQuarticIn(a, b, t, d)
local c = b - a
t /= d
return c * t * t * t * t + a
end
local function Lerp(a, b, t) -- Linear interpolation (if you prefer this)
return a + (b - a) * t
end
local function nwait(t)
local accumulated = 0
repeat
accumulated += RunService.Heartbeat:Wait()
until accumulated >= t
end
--// Functions
local function OnRenderStepped()
-- Set character orientation
local _, CameraYOrientation, _ = Camera.CFrame:ToOrientation()
Root.CFrame = CFrame.new(Root.Position) * CFrame.fromOrientation(0, CameraYOrientation, 0)
-- Calculate speed
local DashSpeed = EaseQuarticIn(_DashSpeed, 0, math.min(tick() - LastDash, _DashDuration), _DashDuration) -- Decelerate towards 0 speed
-- Apply velocity
local MoveDirection = Humanoid.MoveDirection == Vector3.new() and LastMDirection or Humanoid.MoveDirection
LastMDirection = MoveDirection
local DashVelocity = MoveDirection * DashSpeed
local Velocity = Root.AssemblyLinearVelocity
Root.AssemblyLinearVelocity = DashSpeed > 0 and Vector3.new(DashVelocity.X, Velocity.Y, DashVelocity.Z) or Velocity
end
function Dash()
local t = tick()
if t - LastDash >= _DashCooldown and Humanoid.MoveDirection ~= Vector3.new() then -- Won't dash if standing still
LastDash = t
coroutine.wrap(function()
Humanoid.WalkSpeed = 0
nwait(_DashDuration)
Humanoid.WalkSpeed = WalkSpeed
end)()
end
end
function OnInputBegan(Input, Processed)
if Processed then return end
if Input.KeyCode == Enum.KeyCode.LeftShift then
Dash()
end
end
--// Events
RunService.RenderStepped:Connect(OnRenderStepped)
UserInputService.InputBegan:Connect(OnInputBegan)
Just changing the _DashCooldown and _DashDuration to 0.5 should give you the results youâre looking for and as for the player not influencing the dash, the velocity added onto the character should be enough to not be affected by player inputs. If youâre not a fan of how the dash speeds up and whatnot, just change the method thatâs used for the velocity to using the Lerp function instead of the EaseQuarticIn.
local Camera = workspace.CurrentCamera
local Character = script.Parent
local Root = Character.HumanoidRootPart
local Humanoid = Character.Humanoid
local WalkSpeed = Humanoid.WalkSpeed
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local _DashCooldown = 1
local _DashDistance = 60
local _DashDuration = 1
local _DashSpeed = _DashDistance / _DashDuration
local LastDash = 0
local LastMDirection = Vector3.new()
--// Utilities
local function EaseQuarticIn(a, b, t, d)
local c = b - a
t /= d
return c * t * t * t * t + a
end
local function Lerp(a, b, t) -- Linear interpolation (if you prefer this)
return a + (b - a) * t
end
local function nwait(t)
local accumulated = 0
repeat
accumulated += RunService.Heartbeat:Wait()
until accumulated >= t
end
--// Functions
local function OnRenderStepped()
-- Set character orientation
local _, CameraYOrientation, _ = Camera.CFrame:ToOrientation()
Root.CFrame = CFrame.new(Root.Position) * CFrame.fromOrientation(0, CameraYOrientation, 0)
-- Calculate speed
local DashSpeed = Lerp(_DashSpeed, _DashDuration, math.min(tick() - LastDash, _DashDuration)) -- Decelerate towards 0 speed
-- Apply velocity
local MoveDirection = Humanoid.MoveDirection == Vector3.new() and LastMDirection or Humanoid.MoveDirection
LastMDirection = MoveDirection
local DashVelocity = MoveDirection * DashSpeed
local Velocity = Root.AssemblyLinearVelocity
Root.AssemblyLinearVelocity = DashSpeed > 0 and Vector3.new(DashVelocity.X, Velocity.Y, DashVelocity.Z) or Velocity
end
function Dash()
local t = tick()
if t - LastDash >= _DashCooldown and Humanoid.MoveDirection ~= Vector3.new() then -- Won't dash if standing still
LastDash = t
coroutine.wrap(function()
Humanoid.WalkSpeed = 0
nwait(_DashDuration)
Humanoid.WalkSpeed = WalkSpeed
end)()
end
end
function OnInputBegan(Input, Processed)
if Processed then return end
if Input.KeyCode == Enum.KeyCode.LeftShift then
Dash()
end
end
--// Events
RunService.RenderStepped:Connect(OnRenderStepped)
UserInputService.InputBegan:Connect(OnInputBegan)