I have never worked with cameras, and I'm creating a game where I don't want the camera to move, and have only one viewpoint. I've searched around for a bit, and I am not able to find anything. If you can link me to an article or give me a small code snippet, I'd be happy. Thanks!
Camera Manipulation, the bane of early scripters.
To manipulate the Camera
, you need knowledge of math and CFrame
.
Go to the Constructors
topic of CFrame
, and you'll see ways to set CFrame, but what we're interested in is
CFrame.new(Vector3 Pos, Vector3 Point)
This way is the easiest way to set a camera's position in my opinion because it allows it to set the position and direction at the same time.
So, how do we edit the Camera
's CFrame?
The Camera
doesn't actually have a CFrame
property, but rather a CoordinateFrame
property, which is CFrame but longer name.
So, you know how to access the Camera
's CFrame and you know how to set it, so now what?
Well obviously, you need to combine them.
First off, to manipulate the camera, you need to use CurrentCamera
, which is a child of Workspace
.
Second, to manipulate a camera, it needs to be in a LocalScript
, for Server Sided Scripts can't access CurrentCamera
Third, to make a camera that DOESN'T move, you need to set the Camera
's CameraType to Scriptable
.
--Local Script: local cam =game.Workspace.CurrentCamera cam.CameraType = Enum.CameraType.Scriptable print(cam.CoordinateFrame)--the camera's CFrame. cam.CoordinateFrame = CFrame.new(Vector3.new(XPos,YPos,ZPos), Vector3.new(XPoint,YPoint,ZPoint))