Here is a function that moves the camera to a certain CFrame smoothly over a certain amount of time in seconds.
local moveCamera = function(destination, moveTime)
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local destination = {CFrame = moveTime}
local tweenInfo = TweenInfo.new(moveTime, Enum.EasingStyle.Linear)
local cameraTween = game:GetService('TweenService'):Create(camera, tweenInfo, destination)
cameraTween:Play()
end
Note that if you want the camera to move from one place to another, you will need to set the camera CFrame beforehand and then run that function. You can modify the function to what you would like it to be. If you want, you can change the EasingStyle to Enum.EasingStyle.Quad, but I find that Linear works best for the camera.
Yeah, something like that. Just imagine as if the camera were a helium baloon attached to the part. It would be a bit behind the part and when the part stops it would keep on moving forward for a few seconds.
RS.RenderStepped:Connect(function(deltaTime) -- use deltaTime if you want it to depend on player FPS
workspace.CurrentCamera.CFrame:Lerp(workspace.CurrentCamera.CFrame, .2)
end)
Take a look at the comments in the code snippet below~
local Spring = require(script.Spring)
local RunService = game:GetService("RunService")
local part = game.Workspace:WaitForChild("Part")
local camera = game.Workspace.CurrentCamera
--[[
Initialise the spring and set it's dampening and speed value to some value.
]]--
local spring = Spring.new(Vector3.new())
spring.d = 10 -- Dampening
spring.s = 5 -- Speed
--[[
Update function sets the spring target to the part's current position, and
adds some offset so the camera isn't sitting directly inside of the part.
Sets the camera CFrame to the current position of the spring.
]]--
local function update()
spring.t = part.Position + Vector3.new(0, 2, 10)
camera.CFrame = CFrame.new(spring.p)
return
end
--[[
Connect update function to RenderStepped so that the camera is updated
each frame.
]]--
RunService.RenderStepped:Connect(update)
Here is an open-source spring module you can use: Spring.lua (3.2 KB)
This doesn’t take into account the orientation of a part, only the position, but it’s a jumping off point for you.