Fixing straight dashing and making it CURVED! (NOT FIXED)

Hello everybody! I am using a dash script for my game but the dash seems to only pull you in the direction you are facing once, and you cannot turn the direction you want to go until you are DONE dashing.


(Don’t mind the weird GUI bugging out at the bottom left!)

My goal is to make it so the player can curve the direction they are moving as they dash to the direction they are facing so my game can “feel” better to play.

But there’s a problem, I don’t know how to code, and my other friends who know things about scripting don’t know how to fix this either.

May you guys help me with the code and tell me what’s broken because I honestly cant tell how to fix this.

Here’s my script:

local soundId = 4479083227

local Sound = Instance.new('Sound')
Sound.Name = 'PlayerJoinSound'
Sound.Volume = 0.5
Sound.SoundId = 'rbxassetid://'..soundId 
Sound.Parent = workspace 

local UIS = game:GetService("UserInputService")
local char = script.Parent

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://17540489681" 
local anim2 = Instance.new("Animation")
anim2.AnimationId = "rbxassetid://17714783008"

local keybind = Enum.KeyCode.E -- key for ability
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end
	
	if input.KeyCode == keybind then
		canslide = false
		
		local playAnim = char.Humanoid:LoadAnimation(slideAnim)
		playAnim:Play()
		
		Sound:Play()
		
		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 130
		slide.Parent = char.HumanoidRootPart
		print("Dash")
		
		for count = 1, 8 do
			
			wait(0.1)
			print(char.HumanoidRootPart.Velocity.Magnitude)
			slide.Velocity*= 0.8
			if char.HumanoidRootPart.Velocity.Magnitude < 22 then --if player dashes straight into a wall, stop script
				
				
				playAnim:Stop()
				slide:Destroy()
				canslide = true
				local playAnim2 = char.Humanoid:LoadAnimation(anim2)
				
				playAnim2:Play()
				wait(0.2)
				
				playAnim2:Stop()
				
				
				break
			end
			
		end
		playAnim:Stop()
		slide:Destroy()
		canslide = true
	end
end)

This is my third post, so hopefully I am being as supportive as possible! :hidere:

1 Like

You need to use AssemblyLinearVelocity and apply a curve to the velocity based on the current MoveDirection of the Humanoid.

Have you looked into using :Lerp() to slowly add sideways velocity to your default forward movement? I’ve made some modifications to your script to show how that can be done:

local soundId = 4479083227

local Sound = Instance.new('Sound')
Sound.Name = 'PlayerJoinSound'
Sound.Volume = 0.5
Sound.SoundId = 'rbxassetid://'..soundId 
Sound.Parent = workspace 

local UIS = game:GetService("UserInputService")
local char = script.Parent

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://17540489681" 
local anim2 = Instance.new("Animation")
anim2.AnimationId = "rbxassetid://17714783008"

local keybind = Enum.KeyCode.E -- key for ability
local canslide = true

local sidewaysMovementMultiplier = 1
local sidewaysMovementLerpAlpha = 0.2

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end

	if input.KeyCode == keybind then
		canslide = false

		local playAnim = char.Humanoid:LoadAnimation(slideAnim)
		playAnim:Play()

		Sound:Play()
		
		local dashForwardVelocity: Vector3 = char.HumanoidRootPart.CFrame.lookVector * 130
		local dashCFrame = char.HumanoidRootPart.CFrame
		
		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = dashForwardVelocity
		slide.Parent = char.HumanoidRootPart
		
		
		print("Dash")

		for count = 1, 8 do

			wait(0.1)
			print(char.HumanoidRootPart.Velocity.Magnitude)
			
			dashForwardVelocity *= 0.8
			
			local sidewaysVelocity = Vector3.new(0, 0, 0)
			if UIS:IsKeyDown(Enum.KeyCode.A) then
				sidewaysVelocity += dashCFrame:VectorToWorldSpace(Vector3.new(-1, 0, 0)) * dashForwardVelocity.Magnitude * sidewaysMovementMultiplier
			end
			
			if UIS:IsKeyDown(Enum.KeyCode.D) then
				sidewaysVelocity += dashCFrame:VectorToWorldSpace(Vector3.new(1, 0, 0))  * dashForwardVelocity.Magnitude * sidewaysMovementMultiplier
			end
			
			dashForwardVelocity = dashForwardVelocity:Lerp(dashForwardVelocity + sidewaysVelocity, sidewaysMovementLerpAlpha)
			
			slide.Velocity = dashForwardVelocity
			
			
			if char.HumanoidRootPart.Velocity.Magnitude < 22 then --if player dashes straight into a wall, stop script


				playAnim:Stop()
				slide:Destroy()
				canslide = true
				local playAnim2 = char.Humanoid:LoadAnimation(anim2)

				playAnim2:Play()
				wait(0.2)

				playAnim2:Stop()


				break
			end

		end
		playAnim:Stop()
		slide:Destroy()
		canslide = true
	end
end)

You can read up on how :Lerp() works on the docs page for Vectors:

I advice against actually using the script I’ve written and encourage you to use it as an example for your own implementation so you can get an understanding of how it actually works.

1 Like

With a bit of tweaking of my own, I got it to work. Thank you!

1 Like

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