Make mouse move in a circle only?

I’m trying to find a way to make the fake mouse move in a circular direction (clamped from the real mouse’s position):

I have a script but it moves in a square pattern instead of a circular one, and once going closer to the center, it goes to the mouse’s position instead of being in the circle’s pattern position.


This is my current script:

local radius = 200

game:GetService("RunService").RenderStepped:Connect(function()
	local absSize = script.Parent.Parent.AbsoluteSize
	local centerPos = absSize / 2
	local mousePos = Vector2.new(
		game:GetService("UserInputService"):GetMouseLocation().X,
		game:GetService("UserInputService"):GetMouseLocation().Y
	)
	
    script.Parent.Position = UDim2.fromOffset( math.clamp(mousePos.X, centerPos.X - radius, centerPos.X + radius), math.clamp(mousePos.Y, centerPos.Y - radius, centerPos.Y + radius) )
end)
3 Likes
local absSize = script.Parent.Parent.AbsoluteSize
local centerPos = absSize / 2
local mousePos = UserInputService:GetMouseLocation()
local dis = math.min((mousePos - centerPos).Magnitude, radius)
local pos = (mousePos - centerPos).Unit * dis + centerPos
script.Parent.Position = UDim2.fromOffset(pos.X, pos.Y)	

Haven’t tested, should work

4 Likes

Works like a charm. \\\\\\\\\

1 Like

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