Directional Dashing

Is there any way to use move direction to dash in the direction a player is moving?

This is my current dash script:

local plr = plrs.LocalPlayer
while plr.Character == nil do wait() end
local char = plr.Character
local hum = char.Humanoid


local UIS = game:GetService("UserInputService")
local playerGui = game.Players.LocalPlayer.PlayerGui

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://78838763414236"



local keybind = Enum.KeyCode.LeftControl
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()

		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(10,0,10) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.LookVector * 100
		slide.Parent = char.HumanoidRootPart

		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(1.5)
		canslide = true
	end
end) 

However, this only dashes forward. How could I dash in the way I’m moving instead of the way I’m facing?

Yes, there is a way to dash in the direction the player is moving.
Instead of using char.HumanoidRootPart.CFrame.LookVector,
use humanoid.MoveDirection. This is a readonly variable inside all humanoids which describe the actual direction the player is moving. Here’s what the script would look like with the change:

local plr = plrs.LocalPlayer
while plr.Character == nil do wait() end
local char = plr.Character
local hum = char.Humanoid


local UIS = game:GetService("UserInputService")
local playerGui = game.Players.LocalPlayer.PlayerGui

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://78838763414236"



local keybind = Enum.KeyCode.LeftControl
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()

		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(10,0,10) * 30000
		slide.Velocity = humanoid.MoveDirection * 100
		slide.Parent = char.HumanoidRootPart

		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(1.5)
		canslide = true
	end
end)

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