Creating a smooth Shiftlock camera transition

I’ve been trying to implement a smooth transition for entering or exiting shiftlock in my game. I currently use TweenService in the CameraModule function below:

Code in CameraModule
local CameraTweenInfo = TweenInfo.new(0.75, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local LastCameraMode = UserInputService.MouseBehavior
function CameraModule:Update(dt)
	if self.activeCameraController then
		self.activeCameraController:UpdateMouseBehavior()

		local newCameraCFrame, newCameraFocus = self.activeCameraController:Update(dt)

		if self.activeOcclusionModule then
			newCameraCFrame, newCameraFocus = self.activeOcclusionModule:Update(dt, newCameraCFrame, newCameraFocus)
		end

		-- Here is where the new CFrame and Focus are set for this render frame
		local currentCamera = game.Workspace.CurrentCamera :: Camera
		
		if LastCameraMode ~= UserInputService.MouseBehavior and (UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter or UserInputService.MouseBehavior == Enum.MouseBehavior.Default) then
			TweenService:Create(currentCamera, CameraTweenInfo, {CFrame = newCameraCFrame}):Play()
			LastCameraMode = UserInputService.MouseBehavior
		else
			currentCamera.CFrame = newCameraCFrame
		end
		
		currentCamera.Focus = newCameraFocus

		-- Update to character local transparency as needed based on camera-to-subject distance
		if self.activeTransparencyController then
			self.activeTransparencyController:Update(dt)
		end

		if CameraInput.getInputEnabled() then
			CameraInput.resetInputForFrameEnd()
		end
	end
end

This script mostly works, except for the fact that when I enter / exit shiftlock while my character is walking, the tween moves towards the camera’s position relative to the world when the button is clicked, instead to the proper position of the camera. Take a look:

robloxapp-20230504-1801129_Trim.wmv (681.9 KB)

How could I get the camera to move towards it’s “proper” position instead of the “old” one? Is it even possible? Thanks!

1 Like

You can use or find something usefull here.

1 Like

Also, if this solve your problem, mark as solved, to hide it from unsolved list.

I’ll take a look at this for now, seems promising.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.