Skip to content

SetMouseLookCapture

Takes the mouse’s look for the script - the view no longer follows the mouse - or gives it back.

While the script holds the look, the mouse’s moves reach OnMouseLook alone: the player’s view and body stay where they are, the keys still walk. Made for a camera of the script’s own that the mouse turns (SetCamera): an orbit around a character, a cinematic shot. The buttons, the wheel and the cursor key are not taken.

Given back by SetMouseLookCapture(false), a reload of the scripts and the end of the session.

SetMouseLookCapture([on])
Parameter Type
on boolean true (the default) takes the look, false gives it back (optional)

boolean - true when asked

-- an orbit camera around the player while F6 is on
local orbit, yaw, pitch = false, 0, 0.3
function OnKey(key, pressed)
if key == "f6" and pressed then
orbit = not orbit
SetMouseLookCapture(orbit)
if not orbit then ResetCamera(300) end
end
end
function OnMouseLook(dx, dy)
if not orbit then return end
yaw = yaw - dx * 0.004
pitch = math.max(-0.2, math.min(1.2, pitch + dy * 0.004))
end
function OnFrame()
if not orbit then return end
local x, y, z = GetPlayerPos()
if not x then return end
local r = 4
SetCamera(x + math.sin(yaw) * math.cos(pitch) * r, y - math.cos(yaw) * math.cos(pitch) * r, z + 1.6 + math.sin(pitch) * r,
x, y, z + 1.4)
end

OnMouseLook · IsMouseLookCaptured · SetCamera · SetMouseCapture · the The game’s UI for a script group of the index