Change of the direction while dashing

How can i change direction of the dash while i am dashing? (Just like in TSB for example?) I tried many things but i just cant figure it out. Any ideas?

  1. Whats TSB?
  2. What are you using to apply force to do the dash if thats what you are doing
  3. Can we please see some code?
1 Like

TSB is a game called The Strongest Battlegrounds
I am using LinearVelocity to apply force, but when i trigger the dash i cant change direciont while dashing and my character is going in a straight line no matter of the direction i am facing. As i said i tried multiple things but i just dont know to do change it

Here is my code:

function accelerateToVelo(lv : LinearVelocity, targetVelocity : Vector2, accel)
	local velocity : Vector2 = lv.PlaneVelocity
	local deltaV : Vector2 = targetVelocity - velocity

	local _, current_dt = game:GetService("RunService").Stepped:Wait()
	local maxAccel = deltaV / current_dt

	local finalAcc = (maxAccel.magnitude < accel) and maxAccel or maxAccel.Unit * accel

	return Promise.new(function(resolve)
		local e
		local FRAMES_WITH_REACH = 1

		e = game:GetService("RunService").Stepped:Connect(function(time, dt)
			lv.PlaneVelocity = lv.PlaneVelocity + finalAcc * dt

			if((targetVelocity - lv.PlaneVelocity).Magnitude <= finalAcc.magnitude * dt * FRAMES_WITH_REACH) then
				lv.PlaneVelocity = targetVelocity
				e:Disconnect()
				resolve()
			end
		end)
	end)
end

function accelerateToDistance(targetVelocity : Vector2, accTime, totalDistance, cd1, cd2)
	local attachment = Instance.new("Attachment")
	attachment.Parent = HRP

	local LV = Instance.new("LinearVelocity")
	LV.MaxForce = math.huge
	LV.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
	LV.PlaneVelocity = Vector2.zero
	LV.Attachment0 = attachment
	LV.RelativeTo = Enum.ActuatorRelativeTo.World
	LV.PrimaryTangentAxis = Vector3.xAxis
	LV.SecondaryTangentAxis = Vector3.zAxis
	LV.Parent = attachment

	local d1 = 0.5 * (targetVelocity.Magnitude) * accTime
	local d2 = totalDistance - d1
	local a2 = math.abs(-(targetVelocity.Magnitude * targetVelocity.Magnitude)/(2 * d2))


	return accelerateToVelo(LV, targetVelocity, targetVelocity.Magnitude/accTime):andThen(function()
		return accelerateToVelo(LV, Vector2.zero, a2):andThen(function()
			attachment:Destroy()
		end)
	end)
end

local isDashing = false

function onDashKeyPressed(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin and not isDashing then 
		isDashing = true		
		doDash():andThen(function()
			isDashing = false	
		end)
	end
end

CAS:BindAction("DASH_ACTION", onDashKeyPressed, true, Enum.KeyCode.Q)

function doDash()
	local animation = anims["ForwardDash"]
	local movingDir = (HRP.AssemblyLinearVelocity * Vector3.new(1,0,1)).Unit

	if Humanoid.MoveDirection == Vector3.zero then
		movingDir = (Vector3.new(1,0,1) * -HRP.CFrame.LookVector).Unit	
		animation = anims["BackwardDash"]
	elseif UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
		local lastClosest = math.huge
		local animDirection

		for directionName, dirVec in directions do
			local closeness = 1 - (HRP.CFrame * dirVec):Dot(Humanoid.MoveDirection)

			if closeness < lastClosest then
				lastClosest = closeness
				animDirection = directionName
			end
		end

		animation = anims[animDirection .. "Dash"]
	end
	
	animation:Play(.25, 2, 1.2)

	local targetVel = 60

	accelerateToDistance(targetVel * Vector2.new(movingDir.X, movingDir.Z).Unit, 0.04, 18)

	return Promise.new(function(resolve)
		animation.Stopped:Wait()
		resolve()
	end)
end

If you could give some clue i would be very greatful

Hmm ok well in TSB the only real way to turn while dashing to my knowledge is when you have shiftlock enabled and you move you’re mouse, which turns you chararacter, so if you have your dash setup right it should work just fine

1 Like

to my knowledge in TSB when you dash, it takes what direction you’re attempting to dash in (depending on what key you’re pressing or direction you’re moving on accordance to your rootpart) and it’ll constantly set your velocity to that.

for instance say i was moving right or i was holding D on dash it’s basically just be like

local start = time()
local dashTime = .5

local dashSpeed = 26

local plr = game.Players.LocalPlayer
local char = plr.Character
local rootPart = char.HumanoidRootPart

while time() - start <= dashTime do
    rootPart.AssemblyLinearVelocity = rootPart.CFrame.rightVector * dashSpeed
end

this makes it such that if you rotate you will spin and curve whilst always going towards that direction

1 Like

I tried it and i only crashed my studio
Wait ima try to change it a bit

You could get the HumanoidRootPart (thats not affected by animations), and make it face the front of the camera

heres a demonstration of how you can do it:

local UserInputService = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local currentcamera = workspace.CurrentCamera

local dashspeed = 120 -- Change this as you like

local keyW = false
local keyA = false
local keyS = false
local keyD = false

local dashcooldowninseconds = 5 -- Change this as you like

local candash = true

UserInputService.InputBegan:Connect(function(input, gameprocessed)
	if gameprocessed == true then return end
	if input.KeyCode == Enum.KeyCode.Q then
		if candash == false then return end
		candash = false
		local char = plr.Character or plr.CharacterAdded:Wait()
		local rootpart = char:WaitForChild("HumanoidRootPart")
		local attachment = Instance.new("Attachment", rootpart)
		local linearvelocity = Instance.new("LinearVelocity", rootpart)
		linearvelocity.MaxForce = math.huge
		linearvelocity.Attachment0 = attachment

		local lookposition = rootpart.Position + currentcamera.CFrame.LookVector * 50
		rootpart.CFrame = CFrame.lookAt(rootpart.Position, Vector3.new(lookposition.X, rootpart.Position.Y, lookposition.Z))

		if keyS and not keyA and not keyD and not keyW then
			linearvelocity.VectorVelocity = rootpart.CFrame.LookVector * -dashspeed
		elseif keyW and not keyA and not keyD and not keyS then
			linearvelocity.VectorVelocity = rootpart.CFrame.LookVector * dashspeed
		elseif keyA then
			linearvelocity.VectorVelocity = rootpart.CFrame.RightVector * -dashspeed	
		elseif keyD then
			linearvelocity.VectorVelocity = rootpart.CFrame.RightVector * dashspeed					
		end

		game.Debris:AddItem(attachment, 0.1)
		game.Debris:AddItem(linearvelocity, 0.1)
		task.wait(dashcooldowninseconds)
		candash = true
	end
	if input.KeyCode == Enum.KeyCode.W then
		keyW = true
	end
	if input.KeyCode == Enum.KeyCode.A then
		keyA = true
	end
	if input.KeyCode == Enum.KeyCode.S then
		keyS = true
	end
	if input.KeyCode == Enum.KeyCode.D then
		keyD = true
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then
		keyW = false
	end
	if input.KeyCode == Enum.KeyCode.A then
		keyA = false
	end
	if input.KeyCode == Enum.KeyCode.S then
		keyS = false
	end
	if input.KeyCode == Enum.KeyCode.D then
		keyD = false
	end
end)
1 Like

This also doesnt work. I will try to figure it out on my own. If anybody else knowns how to make it work please tell me.

Here’s a workaround I’ve used:

1 Like

Thank you all so much for trying to help. I have found a solution thanks to this linked topic.

1 Like

Is this what your talking about

how when they turn their camera it dashes the way of the camera? thats the best i could explain it

1 Like

Yep. But i managed to do it. However if you know how to make it you can share it with us because it might be more efficient then the way i did it.

I had to same problem with you and i looked at other peoples post and couldnt understand what it was or just it didnt work in the way i intended. but i managed to find my own way like 10 minutes ago but i doubt its more efficient then yours. could you show me what you did then i will tell you mines

I looked at this topic:
https://devforum.roblox.com/t/issues-with-dashing-system/3058697/17
and i realised that it would be better to try and change the script (i am talking about the script from the topic above) for my personal use. I changed everything under 10 minutes and it works flawlessly.

1 Like

Yup this script is way better than mine. I found scripts similar but i get confused on what i need to remove because my dash system for straight is not a regular dash. its like strongest battle grounds where you dash with a ring and debris and then punch. But i recommend using that script 100%

Yeah i know what you are talking bout. Me too. Just need to add cd and hitboxes to it

1 Like

well, i tested the script and it worked as the video that the other person did, but atleast you got the problem solved

1 Like

Thanks again mate. You are a lifesaver

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