I believe adding a variable like this should work:
local z = UIS:IsKeyDown(Enum.KeyCode.W) and -vars.DASH_DISTANCE or UIS:IsKeyDown(Enum.KeyCode.S) and vars.DASH_DISTANCE or 0
local x = UIS:IsKeyDown(Enum.KeyCode.A) and -vars.DASH_DISTANCE or UIS:IsKeyDown(Enum.KeyCode.D) and vars.DASH_DISTANCE or 0
--may need to switch the negatives for the x variable.
So, it would look something like this:
---- dashing
UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.Q and dashDeb == false then
local z = UIS:IsKeyDown(Enum.KeyCode.W) and -vars.DASH_DISTANCE or UIS:IsKeyDown(Enum.KeyCode.S) and vars.DASH_DISTANCE or 0
local x = UIS:IsKeyDown(Enum.KeyCode.A) and -vars.DASH_DISTANCE or UIS:IsKeyDown(Enum.KeyCode.D) and vars.DASH_DISTANCE or 0
if x == 0 and z == 0 then return end
dashDeb = true
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character,workspace.Baseplate}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(humRoot.Position,humRoot.CFrame.LookVector * vars.DASH_DISTANCE,raycastParams)
local rayPos
if rayResult then
local part = rayResult.Instance
if part.CanCollide == true then
rayPos = rayResult.Position
else
rayPos = humRoot.CFrame*CFrame.new(0,0,-vars.DASH_DISTANCE).Position
end
else
rayPos = humRoot.CFrame*CFrame.new(0,0,-vars.DASH_DISTANCE).Position
end
local mover = Instance.new("BodyPosition",humRoot)
mover.Name = "Dash"
mover.MaxForce = Vector3.new(9999999,9999999,9999999)
mover.D = 100
mover.P = 1000
mover.Position = rayPos
debris:AddItem(mover,0.3)
local gyro = Instance.new("BodyGyro",humRoot)
gyro.MaxTorque = Vector3.new(9999999,9999999,9999999)
gyro.D = 100
gyro.P = 1000
gyro.CFrame = humRoot.CFrame
debris:AddItem(gyro,0.3)
spawn(function()
wait(vars.DASH_CD)
dashDeb = false
end)
end
end)
You can use PlayerModule found inside PlayerScripts to determine the direction of the dash, require it at the top of the script like this:
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls();
Then when you want to determine the exact direction you just use Controls:GetMoveVector()
It returns Vector3 with (-1;1) range relative to the camera:
x - left(-1), right(1)
y - always 0
z - forward(-1), backward(1)
Thus resulting in an easy implementation without countless IFs from UIS, plus compatible both with keyboard and gamepad/mobile thumbstick if you would like to rework it a bit for those platforms.
How would i make it so if it plays a matching animation depending on how im moving, for example, if im mowing forward i play forward animation, backward i play backward animation etc…