I’m trying to make a dodge system so that when you dodge, face the direction you wish to dodge in and do the dodge. The player character is facing in the direction of the mouse when they aren’t dodging (which I have managed to get working) but the actual problem is getting the dodge to actually move in the correct direction.
Because it is from a top-down perspective, if you are holding W, it should dodge upwards on the screen and so on. It would also work if you wanted to dodge in a diagonal direction by holding the keys of the direction you wish to dodge in (e.g. S & A for south west). But I have not been able to get a system like this working.
I am currently using LinearVelocity to move the player when they are dodging, if that helps.
That makes the player dodge towards the mouse, I want them to be able to dodge in any direction and face the direction that they are dodging in until they finish the dodge animation before looking at the mouse again.
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local directions = {
[Enum.KeyCode.W] = camera.CFrame.UpVector,
[Enum.KeyCode.S] = -camera.CFrame.UpVector,
[Enum.KeyCode.A] = -camera.CFrame.RightVector,
[Enum.KeyCode.D] = camera.CFrame.RightVector,
}
local function getDirection()
local finalDirection = Vector3.zero
for key, direction in directions do
if UserInputService:IsKeyDown(key) then
finalDirection += direction
end
end
return finalDirection
end