After using Cameratype scriptable, I used Cameratype custom to return the camera back to it’s original place. But for some reason the camera angle goes up the (Y axis).
I tried setting the camera CFrame to it’s original CFrame before setting it to Cameratype custom, or even making a new local script to debug but it just sets the angle to the humanoidrootpart lookvector. I tried setting the camera subject to the humanoid.
(Trying to make the camera in first person stuck while inspecting something)
Sorry if I missed something basic
function Effects(v)
if v == true then
camera.CameraType = Enum.CameraType.Scriptable
elseif v == false then
camera.CameraType = Enum.CameraType.Custom
end
end
------TESTING----
local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
UIS.InputBegan:Connect(function(key,chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
Camera.CameraType = Enum.CameraType.Scriptable
end
end
end)
UIS.InputEnded:Connect(function(key,chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject =
game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
end
end
end)
You should capture the camera’s CFrame (position and orientation) when switching to Scriptable, and then reset the CFrame back to that exact value after switching to Custom.
local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local originalCFrame = nil -- Variable to store the original camera position/rotation
function Effects(v)
if v == true then
camera.CameraType = Enum.CameraType.Scriptable
originalCFrame = Camera.CFrame -- Store the original camera CFrame
elseif v == false then
camera.CameraType = Enum.CameraType.Custom
-- Restore the camera's original CFrame
if originalCFrame then
Camera.CFrame = originalCFrame
end
-- Set the CameraSubject back to the humanoid
Camera.CameraSubject = player.Character:WaitForChild("Humanoid")
end
end
------TESTING----
UIS.InputBegan:Connect(function(key,chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
-- Switch camera to Scriptable and store the CFrame
Effects(true)
end
end
end)
UIS.InputEnded:Connect(function(key,chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
-- Switch camera back to Custom and restore the original CFrame
Effects(false)
end
end
end)
What’s Happening:
originalCFrame = Camera.CFrame: When the camera is set to Scriptable, the current camera position (CFrame) is stored.
Camera.CFrame = originalCFrame: When switching back to Custom, the camera CFrame is restored to its original value.
Camera.CameraSubject = player.Character:WaitForChild("Humanoid"): The camera is set to follow the character’s humanoid after switching back to Custom.
This should prevent the camera from unexpectedly moving upward along the Y-axis when switching back to Custom. If you’re still facing issues, make sure there are no other scripts or forces interacting with the camera while it’s being switched.
Thanks for the reply.
I tried storing the CFrame before and the same problem occurs (Just like what you did), I tried making a new game and published it with no other scripts with just this one local script but it still occurs. I think this problem is on my end? I don’t know for sure. Even in third person once you set it back to cameratype custom, it aligns with the characters lookvector, and camera goes down or up it depends (It doesn’t go back to it’s original angle). If you’d like the testing game is on my inv called “Bug” hold R and release it.
Well, it’d be way easier if I could just edit the game myself. Can you give me permission to edit it? That way I can check everything more closely and hopefully fix it faster.
Well, I don’t think it’s fixed yet. I think it’s doing what it’s supposed to, but I’m not sure if that’s exactly what you wanted. If you’d like to test it, please let me know about the result.
Always happy to help. Also, here’s my suggestion for handling the delay:
local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local originalPosition = nil -- Store the original camera position
local originalRotation = nil -- Store the original camera rotation (only the part without Y-axis tilt)
function Effects(v)
if v == true then
Camera.CameraType = Enum.CameraType.Scriptable
originalPosition = Camera.CFrame.Position -- Store the original position
-- Store the rotation without the Y-axis tilt (we keep only the X and Z rotation)
originalRotation = CFrame.new(Camera.CFrame.Position, Camera.CFrame.Position + Camera.CFrame.LookVector)
elseif v == false then
Camera.CameraType = Enum.CameraType.Custom
-- Set the CameraSubject to Humanoid to follow the character
Camera.CameraSubject = player.Character:WaitForChild("Humanoid")
-- Immediately restore the position and the rotation (only X and Z)
Camera.CFrame = CFrame.new(originalPosition) * originalRotation.Rotation
end
end
------TESTING----
UIS.InputBegan:Connect(function(key, chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
-- Switch camera to Scriptable and store the CFrame
Effects(true)
end
end
end)
UIS.InputEnded:Connect(function(key, chat)
if chat == false then
if key.KeyCode == Enum.KeyCode.R then
-- Switch camera back to Custom and restore the original position with rotation
Effects(false)
end
end
end)
Just remove the delay, what could possibly go wrong, right?
Without the delay it won’t work but with task.wait set to 0 it works pretty okay, but you could still see the frame in a split second where it teleported upwards or downwards. I still could not find anything upon hours of searching the forum. I tried (repeat until wait) and loop, I’ll try to find a work around this, or keep it in. Massive thanks for the help.