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

How do I focus the camera?

Asked by 9 years ago

I want to make it so that the camera focus's on a certain something, and you cant pan around with your mouse or zoom out. The script on roblox wiki does focus the camera, but you can still pan around and zoom out... How do you do it? I used a while true do script, but then it lagged the hell out in studio and everything I did was lost... Please help. Im doing this for a character custimization thing.

2 answers

Log in to vote
0
Answered by 9 years ago
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable -- You could use Fixed, but you might still want to move the camera.
game:GetService("RunService").RenderStepped:connect(function()
    game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(10,50,30) -- You can use a variable if, for example, you want to zoom in or out.
3
    game.Workspace.CurrentCamera.Focus = CFrame.new(0,10,0)
end)
Ad
Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

You want to use Coordinate frame , it has two parameters:

It can set a position for the camera

It can set what the camera is facing

More detailed explaination:

CoordinateFrame:

First of all, CoordinateFrame is the extended name of CFrame. The CoordinateFrame property of the camera is simply the position of the camera.

game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(10,50,30) 
-- Positions camera at 10, 50, 30

Focus:

The Focus property is simply that the camera is looking at. To set the Focus property, you would do it the same was as CoordinateFrame:

game.Workspace.CurrentCamera.Focus = CFrame.new(0,10,0) 
-- Makes the camera look at 0, 10, 0

Setting the Focus will automatically rotate the camera in it's CoordinateFrame position.

Locking the camera:

Sadly, setting these properties does not lock the camera's position. The player can still rotate and move the camera around at their will. Currently there is no efficient way to go about solving this, that I know of. For now, the only way to lock the camera is to set a continuous loop. Example:

while true do
    game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(10,50,30)
    game.Workspace.CurrentCamera.Focus = CFrame.new(0,10,0)
    wait()
end

Answer this question