Cutscene for a 2D platformer isn't working correctly

I’ve been trying to make a cutscene for my 2D platformer but everytime I fire the cutscene, the cutscene starts from the player and not the first camera.

Here’s the code I used for the cutscene. And if you are wondering, the custome camera type is set to custom.

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera

local cutsceneTime = 3

local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

function tween(part1,part2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()
	
	wait(cutsceneTime)
	
	camera.CameraType = Enum.CameraType.Custom
end

wait(2)
game.ReplicatedStorage.Cutscene.OnClientEvent:Connect(function()
	tween(game.Workspace.Camera1,game.Workspace.Camera2)
end)
1 Like

Hello Dogcraft,

I’ve rewritten your code and it works fine on my client, if it does not work for you let me know. the problem might just be the custom camera controller.

local TweenService = game:GetService("TweenService")
local CurrentCamera = workspace.Camera
local cutsceneTime = 3

local tweenInfo = TweenInfo.new(
    cutsceneTime,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.In,
    0,
    false,
    0
)

function tween(part1,part2)
    CurrentCamera.CameraType = Enum.CameraType.Scriptable
    CurrentCamera.CFrame = part1.CFrame
    local tween = TweenService:Create(CurrentCamera, tweenInfo, {CFrame = part2.CFrame})
    tween:Play()
    wait(cutsceneTime)
    CurrentCamera.CameraType = Enum.CameraType.Custom
end

wait(2)

game.ReplicatedStorage.Cutscene.OnClientEvent:Connect(function()
    tween(workspace.Camera1,workspace.Camera2)
end)

Have a great day!

Sorry but it didn’t fix the problem at all. :confused:

What method are you using for your 2D camera?

I’m basically manipulating the camera to look to the side of the player.

Might want to make a variable so that the camera doesn’t update during a cutscene, I think that is what is causing the weird camera movement.

If the problem is that it’s cancelling too early, then you need to adjust the cutscene time.

function tween(part1,part2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()
	
	wait(cutsceneTime)
	
	camera.CameraType = Enum.CameraType.Custom
end

What you could instead do is have the time as an argument for the function to change it based on when it was called.

function tween(part1,part2, cutsceneTime) --notice the extra argument here
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()
	
	wait(cutsceneTime)
	
	camera.CameraType = Enum.CameraType.Custom
end

Remove the cutsceneTime variable and you should be good to call the function with the time.

The didn’t help me at all. This time the cutscene didn’t even work.

Did you not change this line?

tween(workspace.Camera1,workspace.Camera2)

I suggested to add the argument when calling it like so.

tween(workspace.Camera1,workspace.Camera2, 5) --the number here is the time

Ok, it fired, but not in the way I wanted.

It should’ve fired. Only the function was changed.

Anyway, what isn’t working about the cutscene specifically? I’m assuming the issue is that it cancels too early, but we need details.

What I mean is that it’s doing exactly what my problem is.

The thing is, we don’t know what exactly the problem is. Please give us information about the issue.

The problem is that it’s starting from the player and not the first camera.

I watched the video again, and it does seem to be starting from the camera’s initial CFrame.

Exactly. That’s what my problem is.

Can you show the code that makes the camera stay in the sidescroller view when not in a cutscene?

ok sure:

local player = game.Players.LocalPlayer

local camera = workspace.CurrentCamera

player.CharacterAdded:Wait()

player.Character:WaitForChild("Head")

camera.CameraSubject = player.Character.Head

camera.CameraType = Enum.CameraType.Custom

camera.FieldOfView = 70

game:GetService('RunService').Stepped:Connect(function()

camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.new(0,0,30)

end)

Instead of doing:

game:GetService('RunService').Stepped:Connect(function()

camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.new(0,0,30)

end)

You can instead use BindToRenderStep() to unbind it during cutscenes with ease.

The camera script:

local player = game.Players.LocalPlayer

local camera = workspace.CurrentCamera

player.CharacterAdded:Wait()

player.Character:WaitForChild("Head")

camera.CameraSubject = player.Character.Head

camera.CameraType = Enum.CameraType.Custom

camera.FieldOfView = 70

game:GetService("RunService"):BindToRenderStep("Sidescroller", function()

camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.new(0,0,30)

end)

The cutscene script:

local TweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")
local CurrentCamera = workspace.Camera
local cutsceneTime = 3

local tweenInfo = TweenInfo.new(
    cutsceneTime,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.In,
    0,
    false,
    0
)

function tween(part1,part2)
    runService:UnbindFormRenderStep("Sidescroll")
    CurrentCamera.CameraType = Enum.CameraType.Scriptable
    CurrentCamera.CFrame = part1.CFrame
    local tween = TweenService:Create(CurrentCamera, tweenInfo, {CFrame = part2.CFrame})
    tween:Play()
    wait(cutsceneTime)
    CurrentCamera.CameraType = Enum.CameraType.Custom
    runService:BindToRenderStep("Sidescroll", function()
            camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.new(0,0,30)
    end)
end

wait(2)

game.ReplicatedStorage.Cutscene.OnClientEvent:Connect(function()
    tween(workspace.Camera1,workspace.Camera2)
end)

I used the custom camera script that you rewrote, and it doesn’t even work. What it does is that it makes the camera look at the center of the map.