How do i stop this dash from jittering when spammed?

Hey people, I’m having some issues with a dash move that slows down as it progresses by using linear velocity and a for loop.
My dash move works fine for most cases, but when its spammed it seems to reset the character’s position from the previous dash.
I haven’t seen anyone else with the same issue so I thought I’d post something here.

Video:

Code:

function self:DashToMousePos(char: Model, mousePos: Vector3, strength: number, duration: number)
	
	local root = char:FindFirstChild("HumanoidRootPart")
	if not root then return end
	
	local humanoid = char:FindFirstChild("Humanoid")
	
	local currentStrength = strength
	
	-- stop current dash
	if root:FindFirstChild("DashAtt") then print("Oh no") root.DashAtt:Destroy() end
	
	-- make velocity
	local lv = Instance.new("LinearVelocity")
	lv.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	lv.MaxAxesForce = Vector3.new(99999,0,99999)

	local att = Instance.new("Attachment")
	att.Name = "DashAtt"
	att.Parent = root

	lv.Attachment0 = att
	lv.Parent = att
	
	local direction = (Vector3.new(mousePos.X, root.Position.Y, mousePos.Z) - root.Position).Unit
	
	-- ITERATION
	task.spawn(function()
		
		-- RAYCAST PARAMS
		local params = RaycastParams.new()
		params.FilterType = Enum.RaycastFilterType.Include
		params.FilterDescendantsInstances = {workspace.Map}

		for i = 0, duration, 0.01 do -- slow down velocity as dash progresses (0.01 is rate)

			if not root then return end
			if not humanoid then return end
			if not att then return end
			
			-- RAYCASTING
			local raycast = workspace:Raycast(root.Position, direction * 10, params)
			
			if raycast then -- hit something (stop)
				
				lv.VectorVelocity = Vector3.new(0,0,0)
				break
				
			else -- keep going
				lv.VectorVelocity = direction * currentStrength -- set vel
			end
			
			currentStrength -= math.max(currentStrength <= strength * 0.15 and currentStrength or strength / (duration/0.01), 1) -- reduce current strength

			task.wait()

		end
		
		att:Destroy()

	end)
	
end

Btw I’m not looking for a debounce, I want to be able to spam a dash.

each linear velocity is trying to fight the other one’s influence. try making the old one decrease in power when a new one is made while there’s still an old one

1 Like

doesnt calling root.DashAtt:Destroy() do that? or is there some other way? Ive already tried setting the old lv’s vector velocity and max axes force to (0,0,0)

i would probably tween down the old lv’s max axes force, but try whatever until it works.

Why not just make it to where one dash has to complete to use the next one? From what I know this has the same effect.

Otherwise, if you don’t want a debounce and that’s final, try making it to where velocity is found upon a dash input, destroy it then perform the dash.

Because then if you spammed a bunch at once you’d have to wait for all dashes to finish.

I’m pretty sure I did that with

if root:FindFirstChild("DashAtt") then print("Oh no") root.DashAtt:Destroy() end

and the character position seems to revert back to a point in the previous dash after doing so instead of progressing from their current position.

No, it’s effectively a soft debounce that stops the dash input from working until you can actually dash, not a queue.

For this, I would reccomment using attributes or values parented to the character rather than attachments.

This code does not prevent the dash from starting, or destroy the velocity, it simply destroys the pointer that you are already dashing and prints a string. It should ideally look something like this:

if root:FindFirstChild("DashAtt") then print("Oh no") return end

This will prevent the rest of the code from running if you are currently dashing. An alternative could be destroying the velocity.

Turns out the jittering was because of client/server delay, so I just moved the dash script to the client.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.