I’m trying to make a 3D game that also turns into a 2D game at some parts. The script I used to make the camera go from 3D to 2D is a script from this post
after changing some stuff in the script in order to make the camera go into a side-scroller view, I experimented with it and even put it in my own game. My problem is that whenever I die, the camera doesn’t go back to the player. It just stays in place.
here’s the script I used/ modified:
local char = script.Parent
local root = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local partThatChangesStuff = workspace:WaitForChild("cameraChangerPart")--change this to the name of whatever brick you're using. Make sure to change it everytime you duplicate a brick (along with duplicating the code)
local customCameraEnabled = false;
local function enableCustomCamera()
customCameraEnabled = true
game:GetService("RunService"):BindToRenderStep("topDownCamera", 201, function()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(root.Position + Vector3.new(0,3,-40), root.Position)
end)
end
local function disableCustomCamera()
customCameraEnabled = false
cam.CameraType = Enum.CameraType.Custom
game:GetService("RunService"):UnbindFromRenderStep("topDownCamera")
end
--[[
* Checks if the player is in a custom room (standing on the custom part)
* @returns {Part|nil}
]]
local function isPlayerInCustomRoom()
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {partThatChangesStuff}
local result = workspace:Raycast(root.Position, Vector3.new(0,-10000,0), params)
if (result) then
return true
end
return false
end
while wait() do
if (isPlayerInCustomRoom()) then
if (not customCameraEnabled) then
enableCustomCamera()
end
else
if (customCameraEnabled) then
disableCustomCamera()
end
end
end
The only solution I’ve tried so far was putting another camera changer part at the spawn point. It worked, but as soon as you step out of the camera changer at spawn, it goes back to the camera that stays in place.
Please help!