Detecting if a mouse is spinning

I’m currently making a handle system and my current idea is that the player will spin their mouse left/right to move it. Any ideas on how I would achieve this?

https://hadesrbx.co.uk/media/msedge_bzmzMGQCTL.gif (example of what I mean)

1 Like

local NUM_POINTS = 10
local MIN_RADIUS = 50

local mousePositions = {}

game:GetService("UserInputService").InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        table.insert(mousePositions, Vector2.new(input.Position.X, input.Position.Y))

        if #mousePositions >= NUM_POINTS then
            local avgPos = Vector2.new(0, 0)
            for _, pos in ipairs(mousePositions) do
                avgPos = avgPos + pos
            end
            avgPos = avgPos / #mousePositions

            local avgDist = 0
            for _, pos in ipairs(mousePositions) do
                avgDist = avgDist + (pos - avgPos).Magnitude
            end
            avgDist = avgDist / #mousePositions
            if avgDist < MIN_RADIUS then
                print("Mouse is moving in a circle!")
            end
            table.remove(mousePositions, 1)
        end
    end
end)

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