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

So, why can't you simply set the CameraType?

Asked by
kazeks123 195
5 years ago

Currently I am working on a roblox game which requires some camera manipulations. The problem starts whenever I try to set camera type to scriptable:

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

The above would run without any errors while when looking in workspace camera type property would somehow change back to Custom (I imagine it has something to do with roblox's core camera script). It is also proven by the fact that the camera zoom functionality still works as where it shouldn't.

I know that certain camera types, e.g. watch, require proper cameraSubject, otherwise they won't work at all, but it shouldn't be the case with scriptable now should it.

So, the final question is: why can't I simply set the cameraType to scriptable and it actually stay as scriptable?

Additional question would be: which camera types support camera.CFrame, because I'm trying to make camera be in set position while the type being watchable which doesn't really work:

camera.CameraSubject = game.Players.localPlayer.character.Humanoid
camera.CameraType = Enum.CameraType.Watch
camera.CFrame = CFrame.new({custom position})

..the camera is set as watch but is not located in the custom position.

1 answer

Log in to vote
7
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

When a Character is loaded, the camera is automatically reset to become Custom. As a result, when you set the CameraType right at the start of a LocalScript, this is overwrited as soon as the character joins the game. One of the ways to solve this, aside from waiting before setting the CameraType, would be to use a GetPropertyChangedSignal to revert the camera back to Scriptable as soon as it changes.

local Cam = workspace.CurrentCamera
Cam.CameraType = Enum.CameraType.Scriptable
Cam:GetPropertyChangedSignal("CameraType"):Connect(function()
    Cam.CameraType = Enum.CameraType.Scriptable
end)

And if you are looking to edit the CFrame of the camera, Scriptable is the CameraType you are looking for.

0
i agree DeceptiveCaster 3761 — 5y
1
Thankyou for not only answering the question but also for bringing the solution to my problem! The only thing I changed was that I added an if statement before setting camera type so it wouldn't go back to scriptable when I don't want it to. kazeks123 195 — 5y
Ad

Answer this question