Creating a dash; BodyVelocity math or something else?

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)

This should be my best explanation now and also I know whats the problem was @HavocOmega

You could just extend the time of the dash

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

Not sure if this will work, but couldn’t you try manipulate the platform stand property of humanoid?

1 Like

Yes this is really not an good idea. It is too buggy

My two explanation should explain how it will look like the solution

I just want add an time like 0.5 seconds untill I can change the direciton

it seem hard how to make it

You could just change the _DashDuration variable

It is much easier to type it than to create it. So how can I change the _DashDuration then after some seconds to get an goal like:

(look at the last post I did with my explanation)

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.

this is exactly what didnt work. so try it out and send me a video I want see it. I explaind what I want Detailed

Could you maybe try this?

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)

As you can see I can change the direction whenever I do want:

Again what I do want is that:

I pressQ
- Dash starts I cant influence the direction after .5 seconds
I press W,S,D,A after .5 seconds then I change my direction

This is what I want then it will look like this:

So I changed my post a bit now you can work with this explanation it is much better now.

I pressQ
- Dash starts I cant influence the direction after .5 seconds
I press W,S,D,A after .5 seconds then I change my direction

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.

now, nothing do work:

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)

You aren’t using the function correctly which is why it isn’t working

then cant you show me how I could use it correctly?

I think the using of lerp is hard to understand in this thing cuz we seriously dont know with variables we should use for the lerp