Help With Updating Camera Tween

I’m working on a jumpscare system similar to “The Mimic” using TweenService for the transition to the NPC’s CameraPart.

What is the Problem?

The problem is that since the NPC sometimes moves when triggering its jumpscare (unfortunately, I can’t change that), the camera while doing the Tween to CameraPart.CFrame doesn’t update the CameraPart’s CFrame correctly, which makes it go to the position that the script knew before updating.

What do I want to do?

I’d like to know if there’s a way to update the TweenService to a CameraPart.CFrame when the CameraPart moves.

System examples

In DTI (Dress To Impress), when the player goes to do their makeup or change their hair, the camera does a kind of TweenService that updates if the head position changes like this:

As you can see in the video, when the player’s head (which in my case would be the CameraPart) changes position or CFrame, TweenService seems to detect it and immediately moves to the new position of the head (CameraPart).

My Jumpscare System (Simple LocalScript):

ScareEvent.OnClientEvent:Connect(function(ScareConfigurations)
	IsScare = true
	ScareConfigurations.ScareSound:Play()
	Camera.CameraType = Enum.CameraType.Scriptable
	if ScareConfigurations.VignetteScare == true then
		TweenService:Create(ScareVignette, TweenInfo.new(3, Enum.EasingStyle.Quart), {ImageTransparency = 0}):Play()
		TweenService:Create(Vignette, TweenInfo.new(3, Enum.EasingStyle.Quart), {ImageTransparency = 0}):Play()
	end
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
	local StrongCamera = ScareConfigurations.CameraMovement
	if not ScareConfigurations.PlayerScare then
		local TweenCamera = TweenService:Create(Camera, TweenInfo.new(0.3), {CFrame = ScareConfigurations.ScareCamera.CFrame})
		TweenCamera:Play()
		TweenCamera.Completed:Wait()
	end
	task.wait(0.5)
	game:GetService("RunService").RenderStepped:Connect(function()
		if IsScare then
			Camera.CameraType = Enum.CameraType.Scriptable
			if ScareConfigurations.PlayerScare then
				Camera.CFrame = game.Players.LocalPlayer.Character:FindFirstChild("Head").CFrame
			else
				Camera.CameraType = Enum.CameraType.Scriptable
				local randomRotation = CFrame.Angles(
					math.rad(math.random(-StrongCamera, StrongCamera) / 4),
					math.rad(math.random(-StrongCamera, StrongCamera) / 4),
					math.rad(math.random(-StrongCamera, StrongCamera) / 4)
				)
				Camera.CFrame = ScareConfigurations.ScareCamera.CFrame * randomRotation
			end
		end
	end)
	task.wait(ScareConfigurations.ScareTime - 0.5)
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	ScareFrame.Visible = true
	if ScareConfigurations.StopSoundFinal == true then
		ScareConfigurations.ScareSound:Stop()
	end
	if ScareConfigurations.VignetteScare == true then
		TweenService:Create(ScareVignette, TweenInfo.new(3, Enum.EasingStyle.Quart), {ImageTransparency = 1}):Play()
		TweenService:Create(Vignette, TweenInfo.new(3, Enum.EasingStyle.Quart), {ImageTransparency = 1}):Play()
	end
	TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quart), {FieldOfView = OriginFieldOfView}):Play()
	IsScare = false
	Camera.CameraType = Enum.CameraType.Custom
end)

I would like you to help me with this system please. I really appreciate your responses. Thanks.

1 Like

Hello, a possible concept you could use is linear interpolation of the camera’s CFrame every frame to a target CFrame based on Heartbeat/RenderStepped delta. This basically smoothly moves the camera to a target position in a seemingly quadratic/cubic fashion (the farther away, the faster it moves to the target). A lot of games use this for smoothening rapid position changes. Here’s an example:

local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local targetCFrame = CFrame.new(0,0,0) -- set this whenever you wish to update

local lerpFactor = 5 -- higher values = faster movement
runService.Heartbeat:Connect(function(delta)
	camera.CFrame = camera.CFrame:Lerp(targetCFrame, delta*lerpFactor)
end)

Hope this helps! Let me know if you have any questions.

1 Like