Roblox Camera

TabooHarmony/roblox-brain/skills/gameplay/roblox-camera

by TabooHarmony38826be57ee37bcf023e9c2b85681bea3909281cNo licenseListed Oct 9, 2026Updated Oct 9, 2026

Use when scripting Roblox camera behavior, CFrame placement, screen raycasts, first or third-person views, or cutscenes.

Instructions onlySoftware Development
AI-generated overview

Reference guidance for scripting Roblox camera behavior, CFrame placement, screen raycasts and custom views.

What it does
Provides a quick reference for Roblox camera scripting: CameraType options, key camera properties, CFrame operations, a custom camera loop pattern, and screen raycasting methods. It also lists common pitfalls such as client-only behavior, default camera overwrites, and the difference between ScreenPointToRay and ViewportPointToRay. A bundled reference file holds first- and third-person recipes, cutscenes, screen shake, mouse-look and fuller API details.
When to use it
Use when writing custom Roblox camera behavior such as cutscenes, third-person follow or custom rotation. Also useful when manipulating CFrame for placement or rotation, raycasting from the screen, or building a non-default player view.
Requirements
No scripts; instructions only. Requires a Roblox development environment with Luau and access to the Roblox engine API; the bundled reference file is read by the agent.

Roblox Camera

When to Load

Load when scripting custom camera behavior (cutscenes, third-person follow, custom rotation), manipulating CFrame for placement/rotation, raycasting from the screen, or building a non-default player view. Client-only.

Quick Reference

The Camera: workspace.CurrentCamera: one per client. Set CameraType = Scriptable to disable defaults and take full control. Without it, defaults overwrite your CFrame every frame.

CameraType: Fixed, Attach/Watch/Track/Follow (subject-following), Custom (default), Scriptable (no default), Orbital (fixed Y, rotates around player). CameraSubject cannot be nil: setting it reverts.

Key properties: CFrame, CameraSubject, FieldOfView (deg), FieldOfViewMode (Vertical/Diagonal), NearPlaneZ, ViewportSize, HeadLocked, HeadScale, Focus.

CFrame essentials:

OperationLuau
Position onlyCFrame.new(position)
Look at targetCFrame.lookAt(position, target, upVector)
XYZ rotationCFrame.Angles(rx, ry, rz)
Local to worldcf * Vector3.new(0, 0, 10)
Interpolatecf:Lerp(goal, alpha)
Unit axescf.LookVector, cf.RightVector, cf.UpVector

Custom camera loop: always PreRender, never Heartbeat:

luau
camera.CameraType = Enum.CameraType.ScriptableRunService.PreRender:Connect(function(dt)    local desired = CFrame.lookAt(head.Position - offset, head.Position)    camera.CFrame = camera.CFrame:Lerp(desired, math.min(dt * 10, 1))end)

Raycasting from camera: camera:ScreenPointToRay(mx, my) (accounts for GUI inset) vs camera:ViewportPointToRay(mx, my) (raw, NO inset). ScreenPointToRay returns a unit Ray (1 stud); multiply Direction by length for the actual raycast.

Pitfalls:

  • Client-only. Server sets silently dropped.
  • Without Scriptable, defaults overwrite your CFrame every frame.
  • PreRender for camera (visual sync). Heartbeat adds 1-frame lag. RenderStepped still works but is superseded by PreRender.
  • Camera.CFrame lacks VR head rotation; use GetRenderCFrame() for the true view.
  • SetRoll is outdated; apply roll via CFrame.Angles(0, 0, roll) on CFrame.
  • CameraSubject = nil reverts to previous.
  • CFrame.new(pos, lookAt) is legacy (back-compat only); use CFrame.lookAt(at, lookAt) for new code.
  • ScreenPointToRay ≠ ViewportPointToRay (GUI inset). Use ScreenPointToRay for mouse input.

See references/full.md for first/third-person recipes, cutscenes, screen shake, mouse-look, full API.

Source and attribution

Source:TabooHarmony/roblox-braininskills/gameplay/roblox-cameraat commit38826be

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal