Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I lock my camera onto a certain part?

Asked by 4 years ago

How would I go about making a script that will create the same CFrame as a part I want the camera to lock on? I tried using CameraSubject but I think I used it in the wrong way. Anyways, how would I make the script?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Set camera cframe (in localscript) like this:

local function ShowMe(part)
    workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position, part.Position)
end
ShowMe(workspace:FindFirstChildWhichIsA("BasePart", true))

Note that in order to 'lock' onto a part, you'll need to make a loop, something like:

local part = workspace:FindFirstChildWhichIsA("BasePart", true)
local locked = true

while wait() do
    repeat
        if part then
            ShowMe(part)
        end
        game:GetService("RunService").RenderStepped:wait()
    until not locked or not part
end
Ad

Answer this question