✓ Accepted answer
Please be aware that Interpolate currently doesn't work correctly in Studio and you should test this in game.
Firstly, :Interpolate takes three arguments: endPosition, endFocusand duration.
This code must be run in a LocalScript and the CameraType must have been set to scriptable.
The endPosition argument is where the camera will physically end up, for example:
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.TestPart.CFrame, someFocusCFrame, 1)
The camera would smoothly tween to the middle of this part.
endFocus is a little different however, endFocus is the position the camera will face when it finishes tweening.
For example:
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local focus = workspace.TestPart.CFrame + workspace.TestPart.CFrame.lookVector
camera:Interpolate(workspace.TestPart.CFrame, focus, 1)
It can be handy to store an array of parts/Positions to interpolate too, for example:
local targets = {PosOne, PosTwo, PosThree, endFocus}
local duration = 1
for i=1, #targets-1 do
camera:Interpolate(CFrame.new(targets[i]), CFrame.new(targets[i], targets[i+1]), duration)
wait(duration)
end
camera.CameraType = Enum.CameraType.Custom
6 comments
Are you testing this in studio? I can't really tell what this code is doing without seeing the explorer view.
It's complicated, but that parts fine... It basically leads to a part
You haven't asnwered my question about if you're testing in studio or not. (Studio testing is currently broken with interpolate)
Oh yeah I am testing in studo
Publish the game as a new place and test it there
Oh okay it works thanks!