Roblox Camera

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

作者 TabooHarmony38826be57ee37bcf023e9c2b85681bea3909281c无许可证收录于 2026年10月9日更新于 2026年10月9日

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

AI 生成的概览

用于编写 Roblox 相机行为、CFrame 定位、屏幕射线检测和自定义视角的参考指南。

功能
提供 Roblox 相机脚本编写的快速参考:CameraType 选项、关键相机属性、CFrame 操作、自定义相机循环模式以及屏幕射线检测方法。还列出常见陷阱,例如仅限客户端、默认相机会覆盖设置,以及 ScreenPointToRay 与 ViewportPointToRay 的区别。随附的参考文件包含第一人称和第三人称方案、过场动画、屏幕震动、鼠标视角以及更完整的 API 细节。
适用场景
适用于编写自定义 Roblox 相机行为,例如过场动画、第三人称跟随或自定义旋转。也适用于使用 CFrame 进行定位或旋转、从屏幕进行射线检测,或构建非默认玩家视角。
运行要求
无脚本,仅为说明文档。需要具备 Luau 的 Roblox 开发环境并可访问 Roblox 引擎 API;随附的参考文件由智能体读取。

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.

来源与署名

来源:TabooHarmony/roblox-brain位于skills/gameplay/roblox-camera提交38826be

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架