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!