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

How to set the camera's CFrame?

Asked by
gdunn2 54
7 years ago

I know this looks like a stupid question, but I cannot learn camera manipulation to save my life. I've tried so many things, but the camera just stays in the same spot(after i set its CFrame) no matter what. By the way, i have another script that destroys the players character. I've tried to manipulate the camera in another game of mine, but i just could not get it there either. Can some please tell me how set the CFrame correctly?

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CameraSubject = nil

vec1 = Vector3.new(0,8,-45)
vec2 = Vector3.new(0,8,45)

workspace.CurrentCamera.CFrame = CFrame.new(vec1,vec2)
0
This code looks fine. Sometimes the default ROBLOX character scripts spoil camera and control code. The easiest way to disable it is to put a script called 'CameraScript' in StarterPlayerScripts, as mentioned here: http://wiki.roblox.com/index.php?title=API:Class/StarterPlayerScripts duckwit 1404 — 7y
0
You can leave the script blank, too, anything that will override the default script will stop it from interfering. duckwit 1404 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Hi gdunn2. I am not a expert at camera manipulation but from your script, I see two issues.

The first issue is that you didn't give the CurrentCamera anytime to load in, try using a wait(2) before the script or you can write

cam = game.workspace:WaitForChild("CurrentCamera"). 

The second issue is on line 7, you are writing CFrame instead of CoordinateFrame. It should be this

workspace.CurrentCamera.CoordinateFrame = CFrame.new(vec1,vec2)

I'm not 100% certain is line 2 makes a difference since your camera mode is set to scriptable anyways, so I wouldn't change the camera subject. Overall your script should look like this

wait(2)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
vec1 = Vector3.new(0,8,-45)
vec2 = Vector3.new(0,8,45)
workspace.CurrentCamera.CoordinateFrame = CFrame.new(vec1,vec2)

Sorry if this didn't help, I tried atleast and Happy Easter :D

0
No, CFrame is the correct name for the property. CoordinateFrame has been deprecated (marked as no longer in use) and will probably be removed from the engine at some point. Use this tool to track API changes: http://anaminus.github.io/api/class/Camera.html#memberCoordinateFrame duckwit 1404 — 7y
0
Always check the official API (wiki.roblox.com) before making suggestions like that - CoordinateFrame was deprecated over a year ago! Happy Easter :D duckwit 1404 — 7y
0
Thanks, it worked once i added a delay! gdunn2 54 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You use CurrentCamera.CoordinateFrame to change the CFrame of the Camera.

workspace.CurrentCamera.CoordinateFrame = CFrame.new()
0
This is a much shorter answer then mine... Kakitoku 32 — 7y
0
No, 'CFrame' is correct. 'CoordinateFrame' has been deprecated (marked as redundant, to be removed). Check the API history: http://anaminus.github.io/api/class/Camera.html#memberCoordinateFrame duckwit 1404 — 7y
0
Always check the official API before posting answers like this. CoordinateFrame was deprecated in February of 2016. duckwit 1404 — 7y

Answer this question