Help with tweening the camera to a part

hello.

I have a part with a click detector in it.
When you click the part, I want the local player’s camera to tween to a specified camera part.

Then, when the player presses a button, I want the camera to go from the part back to the character.

Ive searched up heaps of different posts and videos and I cannot seem to find one that explains this.

Thanks

You can use TweenService to move the camera to the part

Hello, first you have to set camera CFrame to some part you created, and then tween that part to another part. After that simply create another tween going from part to player’s head, you can try using this:

camera.CameraSubject = character.Humanoid
camera.CameraType = "Custom"
camera.CFrame = character.Head.CFrame --- you can make that into a tween if you want

If you need more help, let me know.

1 Like
local tweens = game:GetService("TweenService")
local userInput = game:GetService("UserInputService")

local part = workspace:WaitForChild("Part")
local click = part:WaitForChild("ClickDetector")

local camera = workspace.CurrentCamera
local oldCamera = camera.CFrame

click.MouseClick:Connect(function()
	click.MaxActivationDistance = 0
	oldCamera = camera.CFrame
	camera.CameraType = Enum.CameraType.Scriptable
	local unit = (camera.CFrame.Position - part.Position).Unit
	local distance = (camera.CFrame.Position - part.Position).Magnitude
	local tween = tweens:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = CFrame.lookAt(camera.CFrame.Position - unit * (distance * 0.8), part.Position)})
	tween:Play()
	tween.Completed:Wait()
	click.MaxActivationDistance = 32
end)

userInput.InputBegan:Connect(function(key, processed)
	if processed then
		return
	end
	
	if key.KeyCode == Enum.KeyCode.F then
		local tween = tweens:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = oldCamera})
		tween:Play()
		tween.Completed:Wait()
		camera.CameraType = Enum.CameraType.Custom
	end
end)

This script works nicely.

Here’s the model file for reproduction purposes.

repro.rbxm (3.6 KB)

The “BasePart” instance goes wherever you desire in the workspace and the local script goes inside the “StarterPlayerScripts” folder.

When the ClickDetector is clicked the camera is tweened to focus on the BasePart of which the ClickDetector is inside. Pressing the “F” key will free the camera’s focus and tween the camera back to its original position.

3 Likes

You could set the camera to Cameramode Scriptable then use the :Interpolate() in the camera to move it using part CFrame, focus part CFrame and the duration.

Don’t know of this is exactly what you are looking for but it is out there.

1 Like

Deprecated tho, sad because its so much easier