I want to achieve multi-directional dodges, I’m making top view story-driven / co-op shooter and I’m trying to make that when a player is holding S then presses Space bar it initiates dash in that direction. the problem is i can’t do it sideways, so started working on a “blocker” when multiple buttons are pressed as an example lets say a player is holding down S and D it disables dashes S and D then it activates the ability to do dash sideways.
Some example
[Variables here]
Instance.new("BodyForce",torso)
torso.BodyForce.Name = "Dodge"
torso.Dodge.Force = Vector3.new(0,0,0)
debounce = false
function DodgeDown()
torso.Dodge.Force = Vector3.new(-14000,1,0)
humanoid.WalkSpeed = 0
wait(0.25)
torso.Dodge.Force = Vector3.new(0,0,0)
wait(0.25)
humanoid.WalkSpeed = 16
end
local function Down()
return UIS:IsKeyDown(S) and UIS:IsKeyDown(Space)
end
local function Input(input, gameProcessedEvent)
if debounce then return end
if Down() then debounce = true
print("Going Down")
DodgeDown()
debounce = false
end
end
You could use a part that doesn’t rotate with the character (has a fixed orientation) and then use lookVector, rightVector on that part to get a cframe for the root to go to, or you could create a cframe with only the position updating.
You could use userInput:IsKeyDown() to detect which keys are down, and then have a dictionary with the directions of them like this (I’m sorry if there are any issues with this cause I didn’t write this in studio):
local keyDir = {
Enum.KeyCode.S = CFrame.new(0,0,10), --Goes ten studs backwards
Enum.KeyCode.D = CFrame.new(10,0,0),
...
}
And then just multiply them like this:
local cframeToGoTo = char.HumanoidRootPart.CFrame
for _,v in pairs(userInput:GetKeysPressed()) do --keysDown would be a table with the keys that are currently down, but check if they are one of WASD.
if keyDir[v] then
cframeToGoTo * keyDir[v]
end
end
--Tween to the cframeToGoTo.
Once again sorry for the late response as I went to sleep.
But this should do it:
New code:
for _,v in pairs(userInput:GetKeysPressed()) do
local keyCFrame = keyDir[userInput:GetStringForKeyCode(v)
if keyCFrame then cframeToGoTo * keyCFrame
end
end
cframeToGoTo is still an Incomplete statement, expected assignment or a function call.
looking for solution
update
so far I found out that’s not the cframeToGoTo issue but this spot in general
for _,v in pairs(userInput:GetKeysPressed()) do
local keyCFrame = keyDir[userInput:GetStringForKeyCode(v)]
if keyCFrame then [keyCFrame] * cframeToGoTo
Hey! I had written a fix for that issue but I redid the big post from earlier, so I forgot about the issue and rewrote the code with the error in yet again.
Replace the if statement with this: if keyCFrame then cframeToGoTo = cframeToGoTo * keyCFrame end
though i missed something …
it may sound dumb on my side but how do I activate it ?
from my understanding, it should drag my character while pressing asdw right?