I am trying to make a dash script that allows the player to dash in 4 different directions, but for some reason, only the forward and backward dash is working…
The code:
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humrp = char:WaitForChild("HumanoidRootPart")
local wKeyDown = false
local aKeyDown = false
local sKeyDown = false
local dKeyDown = false
RunService.RenderStepped:Connect(function()
if UIS:IsKeyDown(Enum.KeyCode.W) then
wKeyDown = true
else
wKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
aKeyDown = true
else
aKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
sKeyDown = true
else
sKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.D) then
dKeyDown = true
else
dKeyDown = false
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q and wKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.lookVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.Q and sKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.lookVector * -100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.A and aKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.rightVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.D and dKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.rightVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
end)
Hey there, It looks like your issue is with the vectors. See both vectors are getting multiplied you should return a negative value
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humrp = char:WaitForChild("HumanoidRootPart")
local wKeyDown = false
local aKeyDown = false
local sKeyDown = false
local dKeyDown = false
RunService.RenderStepped:Connect(function()
if UIS:IsKeyDown(Enum.KeyCode.W) then
wKeyDown = true
else
wKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
aKeyDown = true
else
aKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
sKeyDown = true
else
sKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.D) then
dKeyDown = true
else
dKeyDown = false
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q and wKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.lookVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.Q and sKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = -humrp.CFrame.lookVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.A and aKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = -humrp.CFrame.rightVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
if input.KeyCode == Enum.KeyCode.D and dKeyDown then
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = humrp.CFrame.rightVector * 100
bv.Parent = humrp
Debris:AddItem(bv, 0.1)
end
end)
It is possible to flip a value by changing humrp.CFrame.rightVector * 100 to -humrp.CFrame.rightVector * 100.