I am trying to make an intro cutscene system and I want to be able to stop the camera interpolation and return the camera to the player once the player presses a textbutton
How can I achieve this?
My script is here:
local music = script.Parent.IntroMusic
local cam = workspace.CurrentCamera
local camobj = workspace.IntroTransitions.IntroLocations
game.Workspace:WaitForChild(“SpawnLocation”)
local focus = CFrame.new(0,0,100)
local dur = 3
local active = false
– total = 56
cam.CameraType = Enum.CameraType.Scriptable
print(“Set cam type Init”)
Oh my, I just wanted to say that code is really messy, I don’t recommend doing this. You could do a for i = 1,numberofcameras statement, and just keep changing the camera to Point[i] , this would be a lot easier and cleaner, and would save a lot of space for your code. If you would like an example for this, I can show you.
Interpolation can’t be stopped, which is why it’s recommended to instead use CFrame.Lerp or TweenService (which is a recommendation on the Interpolate page itself). TweenService would be the easiest to work with since you can simply call stop on the running tween.
local cam = workspace.CurrentCamera
local camobj = workspace.IntroTransitions.IntroLocations
local focus = CFrame.new(0,0,100)
local dur = 3
local active = false
game.ReplicatedStorage.IntroEvents.StartIntro.OnClientEvent:Connect(function()
active = true
music:Play()
script.Parent.MainFrame.ViewControl.Disabled = false
cam.CameraType = Enum.CameraType.Scriptable
for i = 1,6 do --we put 6 because 6 is the end
if i <= 5 then
wait(dur)
cam:Interpolate(camobj.Point[i].CFrame,focus,dur)
else
active = false
music:Stop()
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.ReplicatedStorage.IntroEvents.StartLocks:Fire()
end
end
end
I don’t do it often because it may give not precise responses, but you can do another :Interpolate to cancel previous ones
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(0,0,0) --set some starting position
camera:Interpolate(CFrame.new(0, 10, 10), CFrame.new(0, 10, 15), 5) --interpolate
wait(2)
camera:Interpolate(camera.CFrame, camera.CFrame + camera.CFrame.LookVector, 1) --quick interpolate to the current cframe that cancels other interpolate
I tried 1 and 10^-10 for the time for the cancelling :Interpolate both make the camera have a sudden stop.
This should work if your goal is to have the camera tweening until a button is clicked
-- variables
local tween;
local music = script.Parent.IntroMusic;
local cam = workspace.CurrentCamera;
local camobj = workspace.IntroTransitions.IntroLocations;
local dur = 3;
local rep = game:GetService("ReplicatedStorage");
local ts = game:GetService("TweenService");
local plr = game:GetService("Players").LocalPlayer;
local chr = plr.Character or plr.CharacterAdded:Wait();
-- functions
local button = script.Parent.Button --YOUR BUTTON GOES HERE
button.MouseButton1Click:Connect(function()
tween:Cancel();
cam.CameraType = Enum.CameraType.Custom;
cam.CameraSubject = chr.Humanoid;
music:Destroy();
game.ReplicatedStorage.IntroEvents.StartLocks:Fire()
script:Destroy();
end);
local function getParts() -- gets all the points inside of camobj
local i = 0;
for x,y in pairs(camobj:GetChildren()) do
if string.find(y.Name, "Point") ~= nil then
i = i + 1;
end;
end;
return i;
end;
-- core
rep.IntroEvents.StartIntro.OnClientEvent:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable;
music:Play();
script.Parent.MainFrame.ViewControl.Disabled = false;
while true do -- looping forever
cam.CFrame = camobj.Point1.CFrame;
local get = getParts();
for i = 1, get do -- loop through all the points
pcall(function()
local inf = TweenInfo.new(dur, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0);
local goal = {CFrame = camobj["Point"..i+1].CFrame};
tween = ts:Create(cam, inf, goal); -- using tweenservice to tween the camera instead of using Interpolate
tween:Play();
wait(dur);
end);
end;
end;
end);
If I accidentally made any errors, reply so I can edit my response