Hello everyone!!
I’m working on a dash script that lets the player dash depending on what direction they’re moving at. The issue with the script is that it works perfectly fine when dashing while looking forward but if I dash if not facing forward then it still dashes forward. It also dashes me back when looking sideways.
--[[SERVICES]]--
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local Debris = game:GetService("Debris")
--[[PLAYER MODEL]]--
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local RootPart = Character.PrimaryPart
--[[VARIABLES]]--
local DASHCD = false
local DASHSPEED = 150
--[[FUNCTIONALITY]]--
--//Movement functions
local function DASH()
if DASHCD then return end
local WorldDir = Humanoid.MoveDirection
if WorldDir.Magnitude <= 0.01 then return end
DASHCD = true
local LocalDir = RootPart.CFrame:VectorToWorldSpace(WorldDir)
local F = LocalDir.Z -- forward is negative Z in Roblox
local R = LocalDir.X -- right is +X
local TH = 0.5
local Dir
if F <= -TH then Dir = "Forward"
elseif F >= TH then Dir = "Backward"
elseif R >= TH then Dir = "Right"
elseif R <= -TH then Dir = "Left"
else Dir = "Diagonal"
end
local DashVec = Vector3.new(R, 0, F).Unit * DASHSPEED
RootPart.AssemblyLinearVelocity = Vector3.new(DashVec.X, RootPart.AssemblyLinearVelocity.Y, DashVec.Z)
task.delay(0.9, function() DASHCD = false end)
end
--//Binding
ContextActionService:BindAction("DASH", DASH, false, Enum.KeyCode.LeftControl)