Directional Combat Like For Honor

Alright, so I’m trying to recreate For Honor’s combat system, and I have an idea of what to do. But the only thing in my way besides the work is how I would detect if my mouse is directing up, left, or right. Shown in the video:

I’m pretty sure I have seen someone replicate the mouse direction but for an emote menu. Is it possible to replicate the mouse direction specifically just for left, right, and up?

2 Likes

You could possibly do this by using the delta mouseposition between 2 frames or more. Then using the vector to get the angle???

Hey, so I took what you said about using mouse delta position and I got the gist of it. While I got it down, it feels funky and unreliable using delta pos x and y. Can you explain to me what you mean by using delta position between two frames or more. And using vector to get the angles. Apologies, I’m not quite familiar with scripting, at least in this area of scripting.

Since you now have a delta X and Y you can now decide the direction. Use the cross product of the vector created by the X and Y to determine the angle. (actually I realised you can’t use the cross product so just use trigonometry?)

Aii I know it’s bad but thoughts on how I did it?

local function OnRenderStep()
	local Delta = UserInputService:GetMouseDelta()
	
	--|| Direction
	if (Delta.X > -0.0200159997 and Delta.Y < -0.0200159997) and (Delta.X < -0.0200159997 and Delta.Y < 0) then
		Direction = "Up"
		-- Update Indicator
		game.ReplicatedStorage.Update:FireServer("Up")
		for i,image in pairs(script.Parent:GetChildren()) do
			if image:IsA("ImageLabel") then
				if image.Name == "Up" then
					image.ImageTransparency = 0
					image.ImageColor3 = Color3.fromRGB(255,255,255)
				else
					image.ImageTransparency = 0.3
					image.ImageColor3 = Color3.fromRGB(0,0,0)					
				end
			end
		end
	elseif (Delta.X < -0.100079998 and Delta.Y < -0.100079998) and (Delta.X < 0 and Delta.Y < 0) then
		Direction = "Left"
		-- Update Indicator
		game.ReplicatedStorage.Update:FireServer("Left")
		for i,image in pairs(script.Parent:GetChildren()) do
			if image:IsA("ImageLabel") then
				if image.Name == "Left" then
					image.ImageTransparency = 0
					image.ImageColor3 = Color3.fromRGB(255,255,255)
				else
					image.ImageTransparency = 0.3
					image.ImageColor3 = Color3.fromRGB(0,0,0)					
				end
			end
		end
	elseif (Delta.X > 0.100079998 and Delta.Y < -0.100079998) and (Delta.X > 0 and Delta.Y < 0) then
		Direction = "Right"
		-- Update Indicator
		game.ReplicatedStorage.Update:FireServer("Right")
		for i,image in pairs(script.Parent:GetChildren()) do
			if image:IsA("ImageLabel") then
				if image.Name == "Right" then
					image.ImageTransparency = 0
					image.ImageColor3 = Color3.fromRGB(255,255,255)
				else
					image.ImageTransparency = 0.3
					image.ImageColor3 = Color3.fromRGB(0,0,0)					
				end
			end
		end
	end
end

Right now, I am not sure if I’m getting delta positions nicely or not. Specifically I don’t know how I would tell when the mouse delta is in between two positions so it can change directions.

I know this is an older post but I’m currently replicating basically the same thing. Wouldn’t the delta position be different based off of different resolutions? If so having a static check for different directions would only be accurate for one screen resolution?