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.
Syntax
Section titled “Syntax”SetMouseLookCapture([on])| Parameter | Type | |
|---|---|---|
on |
boolean | true (the default) takes the look, false gives it back (optional) |
Returns
Section titled “Returns”boolean - true when asked
Example
Section titled “Example”-- an orbit camera around the player while F6 is onlocal orbit, yaw, pitch = false, 0, 0.3function OnKey(key, pressed) if key == "f6" and pressed then orbit = not orbit SetMouseLookCapture(orbit) if not orbit then ResetCamera(300) end endendfunction 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))endfunction 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)endSee also
Section titled “See also”OnMouseLook · IsMouseLookCaptured · SetCamera · SetMouseCapture · the The game’s UI for a script group of the index
