Camera returns to Player's Head instead of original player cam position

Hello,
I am trying to create a camera that can can view an unview a certain part but however, when the camera returns to the player’s regular camera view, it instead goes to the player’s head first which is something I am unsure of how to address. Does anyone know how to make it go to where the player’s camera view was originally at?

Whoever knows how to resolve this can either reply here or contact me at CyberJorge#0001

-Jorge

Couldn’t you just store the Camera’s CFrame before you move it (name the variable oldCam or something like that) then CFrame it back to that Postion (oldCam) instead of the player’s head

I upvote Scottifly response. Pretty sure this is the best way to do it effeciently.

Thank you for that, I will need to find a way to store the OldCam info which is where I need assistance in scripting to get it working properly.

2 Likes

right after the function above the camera type setting to scriptable, put

local oldCam = cam.CFrame

and then for the tween, put

local tweenstart = tweensvc:Create(cam, set, oldCam)
2 Likes

This solution didn’t work, it appeared to go straight to the player cam instead and does not include animation when going back to the player’s regular camera.

i believe you’d need to do it similarly to how you did the ‘backtoplayer’ variable, except just change it so it goes to the old camera’s cframe instead of the player cframe

I dont know if this is really what you was looking for, but it works with only one button, and makes player camera go to the part, then back to player.

Local script

local tweenService = game:GetService("TweenService")

local button = script.Parent
local tweenPart = game.Workspace.TweeningPart

local currentCamera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local playerModule = require(player.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()
local tweenTime = 1 --Time for tween
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0)

local cooldown = false
local isOnPlayer = true

local playerCameraCFrame

button.MouseButton1Click:Connect(function()
	if cooldown == false then
		cooldown = true
		
		if isOnPlayer == true then
			controls:Disable()
			currentCamera.CameraType = Enum.CameraType.Scriptable
			playerCameraCFrame = currentCamera.CFrame
			local tween = tweenService:Create(currentCamera, tweenInfo, {CFrame = tweenPart.CFrame})
			tween:Play()
			wait(tweenTime)
			button.Text = "Back"
			isOnPlayer = false
		else
			local tween = tweenService:Create(currentCamera, tweenInfo, {CFrame = playerCameraCFrame})
			tween:Play()
			wait(tweenTime)
			button.Text = "View"
			currentCamera.CameraType = Enum.CameraType.Custom
			controls:Enable()
			isOnPlayer = true
		end
		
		cooldown = false
	end
end)

Note: Use only one button, button text will change automatically, but set the text to View as it starts on player.