Skip to content

accessMouseDelta

Returns the movement delta of the mouse in pixels since the last call. Calling this function hides the mouse cursor and fixes it in place, allowing for “endless” dragging.

Capture movement and restore the cursor position once finished.

local delta = ac.accessMouseDelta(false, true, false)

The ac.accessMouseDelta function is essential for implementing custom first-person cameras, 3D orbit controls, or specialized mouse-steering logic. Unlike standard mouse tracking, which stops when the cursor hits the edge of the window, this function locks the cursor’s OS position so movement can be tracked indefinitely.

ParameterTypeRequiredDefaultDescription
rawInputboolean, nil, or stringNonilSet to true for raw input, or "camera" to use raw input only if the user has enabled it in their settings.
restorePositionbooleanNotrueWhether the cursor should jump back to its starting point when released.
forcebooleanNofalseIf true, captures the mouse even if it is currently hovering over a UI window.
TypeDescription
vec2The horizontal and vertical distance moved since the last frame.

Applying mouse movement to a camera orientation.

function script.update()
-- only capture if the right mouse button is held
if ui.mouseDown(ui.MouseButton.Right) then
local delta = ac.accessMouseDelta("camera", true, true)
myCamera.yaw = myCamera.yaw + (delta.x * 0.1)
myCamera.pitch = myCamera.pitch - (delta.y * 0.1)
end
end