Smoother Dashing

I have this code here that is responsable for the dashing. I realised that the dashing is smooth except for the fact that when the velocity is done. The user stops moving for a moment and it ruins the flow fo the movement any idea how to fix that?

local Velocity = {}

function Velocity.ApplyDashVelocity(humanoidRootPart, dashDirection, dashForce, dashDuration, easingFunction)
	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.MaxForce = Vector3.new(1, 0, 1) * 80000  -- Only XZ plane
	bodyVelocity.P = 12500
	bodyVelocity.Parent = humanoidRootPart

	local startTime = tick()

	local function updateDash()
		while tick() - startTime < dashDuration do
			local elapsedTime = tick() - startTime
			local t = elapsedTime / dashDuration
			local easingFactor = easingFunction(t)

			local currentLookVector = humanoidRootPart.CFrame.LookVector

			local dashDirectionVector = Vector3.new(0, 0, 0)
			if dashDirection == "Front" then
				dashDirectionVector = currentLookVector
			elseif dashDirection == "Back" then
				dashDirectionVector = -currentLookVector
			elseif dashDirection == "Left" then
				dashDirectionVector = -humanoidRootPart.CFrame.RightVector
			elseif dashDirection == "Right" then
				dashDirectionVector = humanoidRootPart.CFrame.RightVector
			end

			local targetVelocity = dashDirectionVector.Unit * dashForce * (1 - easingFactor)
			bodyVelocity.Velocity = targetVelocity

			task.wait()
		end

		bodyVelocity.Velocity = Vector3.new(0, 0, 0)
		bodyVelocity:Destroy()
	end

	task.spawn(updateDash)
end

return Velocity
1 Like

I’d first reccomend replacing what you’re doing with easing function with a tween. This would save you the need to use a loop to update the dash’s direction/force.

Assuming easingFunction goes down to 0, that is probably the reason why the character stops moving. There’s a period of time where the force is near-zero yet still active, making the player unable to do anything.

The easy solution is to just have it tween down to 10-25% instead of 0. Alternatively you could try experimenting with VectorForces since they apply a force instead of a velocity.