Making a dash system

Im currently working on a dash system, except Im having some issues.

First off, the most annoying one. Flinging.

Since Im using a linear velocity, if you dash and hit the floor your character usually starts freaking out lol.

The other issue is that I would like it so if your body turns, the force of your dash continues in that direction.

I have no idea how to solve either issue, so I was hoping someone here might be able to help!

Action Handler Section

local function OnActionTriggered(Action:string, State:Enum.UserInputState)
	local Begin = State == Enum.UserInputState.Begin
	
	Actions[Action] = Begin
	
	-- // Main //
	if Action == 'Dash' and Begin then
		local MoveDirection:Vector2 = MovementHumanoid.MoveDirection
		
		-- // Values
		
		local RootCFrame = Character.PrimaryPart.CFrame
		local Force = 0
		local DirectionString = nil
		local DirectionVector = nil
		
		if MoveDirection.Y == 1 then 
			DirectionString = 'Forwards'
			DirectionVector = RootCFrame.LookVector
		elseif MoveDirection.Y == -1 then 
			DirectionString = 'Backwards'
			DirectionVector = -RootCFrame.LookVector
		elseif MoveDirection.X == 1 then 
			DirectionString = 'Right'
			DirectionVector = RootCFrame.RightVector
		else
			DirectionString = 'Left'
			DirectionVector = -RootCFrame.RightVector
		end
		
		print(DirectionString, MoveDirection)
		
		-- // Cooldown
		
		if DirectionString == 'Forwards' or DirectionString == 'Backwards' then
			if Cooldowns.FrontDash then return end
			Cooldowns.FrontDash = true
			Force = -100
		else
			if Cooldowns.SideDash then return end
			Cooldowns.SideDash = true
			Force = 50
		end
		
		-- // Dash //
		
		local Velocity = Instance.new('LinearVelocity')
		local Length = 2
		
		Velocity.Attachment0 = Character.PrimaryPart:FindFirstChild('RootAttachment')
		Velocity.MaxForce = math.huge
		Velocity.VectorVelocity = DirectionVector * Force
		Velocity.RelativeTo = Enum.ActuatorRelativeTo.World
		
		Velocity.Parent = Character.PrimaryPart
		
		-- // Queue
		local Item = {
			Start = tick(),
			End = tick() + Length,
			DirectionString = DirectionString,
			Velocity = Velocity,
			Force = Force
		}
		
		table.insert(Queues, Item)
		
		-- // Finish Cooldown
		task.wait(Length)
		Velocity:Destroy()
		
		if DirectionString == 'Forwards' or DirectionString == 'Backwards' then
			task.wait(0)
			Cooldowns.FrontDash = false
		else
			task.wait(0)
			Cooldowns.SideDash = false
		end
	end
end

Renderstep to update the Velocity, which seems to not work :sob:

RunService.RenderStepped:Connect(function(DeltaTime)
	
	-- // Queues //
	for Index, Queue: {Start:number?, End:number?, Action:string} in Queues do
		
		-- // Remove Queue
		if Queue.End then
			if tick() >= Queue.End then
				table.remove(Queues, Index)
			end
		end
		
		-- // Run //
		if Queue.Action == 'Dash' then
			local Velocity:LinearVelocity = Queue.Velocity
			local Direction = Queue.DirectionString
			local RootCFrame = Character.PrimaryPart.CFrame
			
			assert(Velocity, 'No Velocity Found')
			
			if Direction == 'Forwards' then
				Velocity.VectorVelocity = (RootCFrame.LookVector * Queue.Force) * 0.8
			elseif Direction == 'Backwards' then
				Velocity.VectorVelocity = (-RootCFrame.LookVector * Queue.Force) * 0.8
			elseif Direction == 'Right' then
				Velocity.VectorVelocity = (RootCFrame.RightVector * Queue.Force) * 0.8
			elseif Direction == 'Left' then
				Velocity.VectorVelocity = (-RootCFrame.RightVector * Queue.Force) * 0.8
			end
		end
	end
end)

PS Queues is just a table, nothing special

Thanks in advanced!

Disable the Ragdoll humanoid state, fallingdown humanoid state, and probably physics state. That disables flinging I think

2 Likes

Sad to say, but its still flinging, not as much, but it still happens :sob:

Change this to like a really high number or somethin’ like 50000

1 Like

Well this fixed the fling issue!

Thanks!

1 Like

Well I figured out the issue with the dashing, it wasnt being triggered!

:sob:

so what should I set as the solution cause you two both said things that helped

To turn the Velocity as the character turn

  • You could update the Velocity.VectorVelocity during runtime
  • Or set Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0, and add an Attachment to the Root Part, while making sure the Attachment is oriented properly.