Ok so, i have already made a script where i made a region3.
When you are inside that region3 the camera will tween to a 2d view. Now, i made so that when you walk outside of the region the cameratype will be custom which resets the camera back to normal.
But i want it to tween back to the camera smoothly like it did when i entered the region.
Does anyone here know how to tween a camera back?
and i dont want it to copy the location that it was and tween it back to that location since my character is able to walk out from other parts of the region!
Here is my code so far!
local CutCam = game.Workspace.CameraForCutscene.CutsceneCamera local Found = false local player = game.Players.LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local camera = game.Workspace.CurrentCamera local SoundregionsFolder = game.Workspace.Regions local OrientationPart = game.Workspace.CameraForCutscene.OrientationPart game:GetService("RunService").Stepped:Connect(function() CutCam.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(1,1,3) CutCam.Orientation = player.Character.HumanoidRootPart.Orientation + Vector3.new(20,0,0) end) local cameraCFrame = workspace.CurrentCamera.CFrame local TS = game:GetService("TweenService") while wait(0.1) do local TweenBackInfo = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0) local Back = {CFrame = cameraCFrame} local TweenBack = TS:Create(camera,TweenBackInfo,Back) for i, v in pairs(SoundregionsFolder:GetChildren())do Found = false local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2)) local Parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants()) for _, part in pairs(Parts) do if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then print("Player Was Found") Found = true break else Found = false print("Player Was Not Found") break end end if Found == true then print("Player Was Found") camera.CameraType = Enum.CameraType.Scriptable local TweeningInfoCutScene = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0) local CameraCutSceneCF = {CFrame = CutCam.CFrame} local TweenCameraCutScene = TS:Create(camera,TweeningInfoCutScene,CameraCutSceneCF) TweenCameraCutScene:Play() break end if Found == false then print("Player Was Not Found") camera.CameraType = Enum.CameraType.Custom end end end
Use something like camera.CFrame:Lerp(player.Character.HumanoidRootPart.Position * CFrame.new(1,1,3), .3)
. Lerping is pretty useful for making something go smooth. It will also edit the rotation, as CFrame does this automatically. You can learn more about it here: https://developer.roblox.com/en-us/api-reference/datatype/CFrame
I hope this helped!