Hi, I’ve been trying for days to make a game where the 2d camera becomes at some point in the game a 3d camera (the defaut roblox camera, but in first person).
The problem is that the camera is stuck in a certain position and there is no way to rotate it.
This is the script I used to reset the camera:
local player = game.Players.LocalPlayer
local camera = game.workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = player.Character.Humanoid
This is the 2d camera script:
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
game:GetService('RunService').Stepped:Connect(function()
camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position * CFrame.new(0, 0, 15)
end)
2d camera script is disabled when camera reset script is enabled.
(Sorry if I did something wrong in the post, it’s the first time I’ve done one)
Sometimes there is a problem when you set the CameraType to Custom it doesn’t change (at least I remember this happening).
If my assumption is right, and this is the reason why this is happening, considering repeatdly changing the CameraType until it is set to Custom.
I would assume that this is where you are setting the angle for rotation, if so, try using CFrame.Angles() or CFrame.fromEulerAnglesXYZ() instead (They do the same thing). You will also want to make sure that you are using radians for that.
Radians have nothing to do with scripting, they are just another form of measuring angles.
A radian is a circles radius put around the arc of the circle. It fits exactly 2π (pi) times around the circle.
A normal circle has 360 degrees in it, which is also 2π radians in it. The conversion for radians to degrees is (angle in radians) * 180/π or math.deg(angle) and from degrees to radians is (angle in degrees) * π/180 or math.rad(angle)
here is a simple diagram showing this:
this shows the simple conversions from the most common angles to their radian form.
This video also explains what a radian is pretty well.
In ROBLOX, when you use CFrame angles, is takes in a number in radians, so you will just need to make sure to use the radians when you input an angle that you want to put in.
Hope this will help you to understand! Have a merry Christmas!
Sorry for the late reply, but I didn’t quite understand what to do. I just want to reset the camera to put it in first person, but I can’t find the solution.
Do you mean the camera is stuck at one position every time you spawn in, and it still gets stuck there even if you disable the script (like you’ve mentioned)?
If your local script is named CameraScript, try renaming it to something else.
The camera was stuck when I put its type as custom, but now I’ve solved it. The problem is that now I can’t move the camera, nor can I put it in first person
In that case, I think you need to disconnect the Stepped connection so that the camera’s CFrame isn’t constantly being set to their back. This will let them move their camera around normally.
Something like…
local connection = game:GetService('RunService').Stepped:Connect(function()
camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position * CFrame.new(0, 0, 15)
end)
...
if TScript.Disabled == false then
connection:Disconnect()
...
end
…, where “...” is whatever code you need to have, should solve the problem of the camera snapping back.
I also noticed this line in particular doesn’t seem right because you can’t multiply a Vector3 with a CFrame, and there’s a “)” missing.
Thanks for trying to help me :), but unfortunately it didn’t work. On the line where you said I wrote it wrong, I just wrote it wrong here, in studio it’s normal.