Directional dodging/rolling from top-down camera?

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.

1 Like

Would I still need to get the mouse’s position or raycast? I’m still trying to figure it out.

Try this

  • Find the Direction (Unit) measurement
    You’ll need two vector3s for this.

V1 = Vector3.new(hrp.X, 0, hrp.Z) [hrp representing root part]
V2 = Vector3.new(mouse.X, 0, mouse.Z) [mouse representing mouse.hit]

local direction = (V1 - V2).Unit

  • Input Direction into existing code

I’ll use LinearVelocity type as an example, which it seems you have chosen to use.

In this context, lets assume the player just pressed the key to dodge.

–existing code–
LinearVelocity.LineDirection = direction
LineVelocity = 10 --example dodge interval–
task.delay(.5, function()
LineVelocity = 0
end)
– any other necessary code like debounce

Please note this should be done completely on the client! Speed and teleport hacks exist regardless of your movement system.

Let me know if you have issues or concerns.

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.

CFrame.LookVector, CFrame.RightVector, CFrame.UpVector might help you?

I don’t understand what a top-down camera is so I can’t help you much. Maybe if you can provide a screenshot?

when the camera is facing downwards above the play area

{7E5BAFED-FB31-405B-8A09-57F16A30086B}
V (the camera) is facing downwards on the subject (player)

I have solved it myself, sorry for wasting your time. I had to use MoveDirection.

1 Like
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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.