4 way melee system similar to G&B

I’m making a melee system and I would like to have a 4 way melee system similar to “Guts & Blackpowder” where the position of your mouse is the direction you will swing in, How could I achieve this?

2 Likes

Here’s a code I made that may help.


-- User Input Service
local UserInputService = game:GetService("UserInputService")

-- Get the screen size
local workspace = game:GetService("Workspace")
local ViewportSize = workspace.CurrentCamera.ViewportSize

-- Center of the screen
local screenCenter = ViewportSize / 2

local function mousePosition()
	local mousePosition = UserInputService:GetMouseLocation()
	local relativePosition = mousePosition - screenCenter
	
	-- Check the quadrant
	if relativePosition.X < 0 and relativePosition.Y < 0 then
		-- Top Left
		print("Mouse is in the Top Left", relativePosition)
	elseif relativePosition.X > 0 and relativePosition.Y < 0 then
		-- Top Right
		print("Mouse is in the Top Right", relativePosition)
	elseif relativePosition.X < 0 and relativePosition.Y > 0 then
		-- Bottom Left
		print("Mouse is in the Bottom Left", relativePosition)
	else
		-- Bottom Right
		print("Mouse is in the Bottom Right", relativePosition)
	end
end


UserInputService.InputBegan:Connect(function(hit, isTyping)
	if isTyping then return end
	
	-- M1 to check mouse position
	if hit.UserInputType == Enum.UserInputType.MouseButton1 then
		mousePosition()
	end
end)

This code checks which quadrant of the screen your mouse is within (e.g. Top left, Top right, Bottom left, Bottom right). By pressing left click, you’ll find the mouse position.

You can change the code up a bit if you want according to your gameplan. Hope this helps!

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