Hey all, quite frankly im ashamed to ask this as it’s such a simple task, however, I can’t seem to do it, despite having done this successfully probably hundreds of times in the past.
Simply, I want to set the camera subject and camera type to what they need to be to focus directly on the player character. I currently change the camera subject and use interpolation for an effect ingame, then run this to move the camera back to default character focus, but when I run both this code;
I end up with a black screen. I’ve tried repeating the code at intervals, changing it’s order, and a lot more but I just can’t seem to get it working. Here’s a useless picture of what the screen looks like:
It still doesn’t work, I realise this is very likely a problem with the surrounding code, so here it is just in case I’m being an idiot and not seeing something obvious:
:FindFirstChildOfClass("Humanoid") is the same thing, and I frequently change the name of the player’s humanoid for scripts in the game. I gave it a try anyway and no luck
Always works for me so I don’t think the code you posted is the issue. Are you sure another script isn’t stopping it being set or immediately changing it back?
I also tried setting the camerasubject and cameratype to something different then setting it back in a blank baseplate and it worked. Either it’s something to do with Interpolate or I’m unknowingly manipulating the camera elsewhere.
I’m able to accomplish this simply by storing the CurrentCamera CFrame and Focus in a variable before tweening/interpolating the camera. When I need to tween/interpolate back to the Player I just use the values from the Variables I stored them in, so like this:
(Here’s a .rbxl for ease of access, just hit Play and test it out) CamTween.rbxl (16.9 KB)
local tweenService = game:GetService('TweenService')
local currentCamera = workspace.CurrentCamera
local isViewing = false
local orginCameraCFrame = nil
local originCameraFocus = nil --IF USING currentCamera:Interpolate
local partToTweenTo = game.Workspace.partToTweenTo
script.Parent.MouseButton1Click:connect(function()
if not isViewing then
isViewing = true
currentCamera.CameraType = Enum.CameraType.Scriptable
orginCameraCFrame = currentCamera.CFrame
originCameraFocus = currentCamera.Focus --IF USING currentCamera:Interpolate
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0)
local tweenGoal = {CFrame = partToTweenTo.CFrame}
local tweenAnim = tweenService:Create(currentCamera, tweenInfo, tweenGoal)
tweenAnim:Play()
elseif isViewing then
isViewing = false
currentCamera.CameraType = Enum.CameraType.Scriptable
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0)
local tweenGoal = {CFrame = orginCameraCFrame}
local tweenBackAnim = tweenService:Create(currentCamera, tweenInfo, tweenGoal)
tweenBackAnim:Play()
tweenBackAnim.Completed:Connect(function(playbackState)
currentCamera.CameraType = Enum.CameraType.Custom
end)
end
end)
If you don’t want to bother re-tweening back to the player at the end, just remove all of the tween bit’s as well as the currentCamera.CameraType = Enum.CameraType.Scriptable, and just have currentCamera.CameraType = Enum.CameraType.Custom.
If you do decide to keep the tween at the end I suggest either anchoring the Player’s torso or preventing them from moving, as if they move they are at a different position than the one saved in the variable.
Hey! I tried your script but it isn’t seem to be working? It just set it to the origin when I click back. Here’s a video and my script:
local camera = workspace.CurrentCamera -- our camera
local player = game.Players.LocalPlayer -- our player
local characterCreation = script.Parent.Parent.Parent
local TS = game:GetService("TweenService")
local orginCameraCFrame = nil
local originCameraFocus = nil
local isViewing = true
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Quart, -- EasingStyle
Enum.EasingDirection.Out -- EasingDirection
)
orginCameraCFrame = camera.CFrame
originCameraFocus = camera.Focus
script.Parent.MouseButton1Click:Connect(function()
if characterCreation.Enabled == true and isViewing == true then -- if the editor frame is already visible
local findEditorFolder = workspace:WaitForChild("EditorFolder")
--local findEditorFolder = workspace:WaitForChild(player.Name.."EditorFolder") -- we look for the folder where all our camera stuff is inside of it (in workspace)
if findEditorFolder then -- if it was found then..
characterCreation.Enabled = false and isViewing == false
camera.CameraType = "Scriptable" -- we actually just want to change the camera back to normal, we do that by changing the camera type to custom
camera.CameraSubject = workspace:WaitForChild(player.Name).Humanoid -- the subject to the player's humanoid
--local tweenOut = TS:Create(camera, tweenInfo, {CFrame = workspace:WaitForChild(player.Name).Head.CFrame})
local tweenOut = TS:Create(camera, tweenInfo, {CFrame = orginCameraCFrame})
tweenOut:Play()
tweenOut.Completed:Connect(function(playbackState)
camera.CameraType = Enum.CameraType.Custom
end)
end
script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = 16
script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.JumpPower = 50
end
end)
It appears that the solved solution broke after interpolation was deprecated. To save the original position and orientation of the camera I sorta created a janky method that feels caveman like but it gets the job done. What I did was:
(I basically created a new part with the same CFrame as the current camera so I can have the camera tween to the new part’s cframe, and after the cutscene is done I just delete the part, the transparency is 0 just so I can see what is going on but in game it should be set to 1)