Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Manipulating Camera not working. Someone fix?

Today i was trying to script a LocalScript what should move the Players camera to a Part's position and show a room without roof.

local camera = workspace.CurrentCamera
local part = workspace.CameraPart

wait(1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = part
camera.CoordinateFrame = CFrame.new(part.Position)
camera.CoordinateFrame = CFrame.new(-56.1, 26.5, -117.5)
camera.CoordinateFrame = CFrame.Angles(0,180,0)

When i run it, the camera is at the "part"'s position but it does not rotate to to the room, and if i switch the following part

camera.CoordinateFrame = CFrame.new(-56.1, 26.5, -117.5)
camera.CoordinateFrame = CFrame.Angles(0,180,0)

then it rotates the camera but it does not moves the camera to the "part"'s position

2 answers

✓ Accepted answer

Your problem is that you keep overwriting the Camera's CFrame. To combine the CFrames you have to multiply them.

Also, CFrame.Angles requires radians, not degrees. To transform degrees to radians, you can use math.rad function.

And from what I gathered, the CFrame containing coordinates is the same position that the part is at, so it's redudant.

local camera = workspace.CurrentCamera
local part = workspace.CameraPart

wait(1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = part
-- CFrames can by combined by multiplying. You can also add vectors to them
camera.CoordinateFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(180), 0)

You should read some more information on CFrames: http://wiki.roblox.com/index.php?title=CFrame

So you'll need to revise CFrames before continuing this.

What you are doing is setting the cframe to the position, then setting the cframe to the angle...

The correct format is:

local NewCFrame			= CFrame.new(x, y, z) *CFrame.Angles(xr, yr, zr);

Here's the wiki page

This discussion is preserved as it was. New answers, comments, and votes are closed.