pesde goatsoft / lucy

useDrag

Lucy.useDrag tracks dragging gestures that start with a press on target (left mouse button or one touch finger). Once a drag starts, moving anywhere on screen continues it, and releasing ends it. Positions and deltas are in screen pixels.

Usage

local drag = Lucy.useDrag(target, options)
ArgumentTypeDefaultWhat it does
target`GuiObjectRef<GuiObject?>`required
optionstablerequiredCallbacks and options

Options

OptionTypeWhat it does
onStart(point)(point: Vector2) -> ()Called on press with the screen position
onMove(delta, point)(delta: Vector2, point: Vector2) -> ()Called as the pointer moves, with total delta and current position
onEnd(delta)(delta: Vector2) -> ()Called when the pointer releases, with the total delta
disabledMaybeRef<boolean>Stops new drags starting and ends any active drag

Returns

NameTypeWhat it is
dragging()() -> booleantrue while dragging
delta()() -> Vector2Total movement from the press (Vector2.zero when idle)
cancel()() -> ()Stops the current drag and calls onEnd

Example: spin an avatar preview

Drag across the wardrobe viewport to spin the dancer model:

local function AvatarTurntable(h)
    local angle = Lucy.ref(0)
    local startAngle = 0
    local viewport = Lucy.ref(nil)

    Lucy.useDrag(viewport, {
        onStart = function()
            startAngle = angle()
        end,
        onMove = function(delta)
            angle(startAngle - delta.X * 0.015)
        end,
    })

    return Lucy.new "ViewportFrame" {
        [Lucy.instance] = viewport,
        Size = UDim2.fromOffset(240, 320),
    }
end