How to make revolving camera for title screen?

So basically I want to make the camera revolve around the center of this room (which is that gray part in the picture) while on the title screen.

I’ve looked everywhere and tried everything I could find and finally got to what is in the script below, but when the camera revolves, it’s inside of the gray part and is in the exact center of the room when I want it to be revolving around the part. I’m not sure how to offset the camera so it isn’t in the center but looking at the center.

Also, when I press the play button, it stops the tween and rotation, but the camera doesn’t return back to the player like normal. It stays inside the part and in the center of the room.

Here’s the localscript I have inside the title screen GUI

local TweenService = game:GetService("TweenService")
local Camera = game.Workspace.Camera
local Looping = true
local CameraSubjectPart = game.Workspace:WaitForChild("TitleCam") --Gray part in center of room
local RotationLength = 15

repeat wait() until Camera.CameraSubject ~= nil

Camera.CameraType = Enum.CameraType.Attach
Camera.CameraSubject = CameraSubjectPart
script.Parent.Parent.Enabled = true

local Info = TweenInfo.new(RotationLength, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local RotateTween = TweenService:Create(CameraSubjectPart, Info, {CFrame = CameraSubjectPart.CFrame * CFrame.Angles(0, math.rad(-120), 0)})

local Camera = game.Workspace.Camera --When the play button is clicked it stops the rotation
script.Parent.Play.MouseButton1Click:Connect(function()
	Camera.CameraType = Enum.CameraType.Custom
	script.Parent.Parent.Enabled = false --The ScreenGui (Title screen) goes away
	Looping = false
	RotateTween:Pause()
end)

while Looping do
	if not Looping then return end
	RotateTween:Play()
	wait(RotationLength)
end

For this I wouldn’t recommend using Tweens, since you can’t really tween a revolving object or a circular motion at all.

One method I would use, a little inefficient, but here’s some code:

repeat wait() until Camera.CameraSubject ~= nil

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = CameraSubjectPart
script.Parent.Parent.Enabled = true

local PlayButtonClicked = false
local Radians = 0

local RS = game:GetService("RunService")
repeat
	Radians = Radians + 1 -- edit the 1 to increase the speed
	if Radians >= 360 then
		Radians = 1
	end

	local OriginCF = CameraSubjectPart.CFrame * CFrame.Angles(0,math.rad(Radians),0)
	local RevolvePosition = OriginCF + OriginCF.LookVector * 10 -- edit the 10 for distance from the object

	Camera.CFrame = CFrame.new(RevolvePosition.Position, CameraSubjectPart.Position)

	RS.RenderStepped:Wait()
until PlayButtonClicked == true

Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
1 Like

For this line:

local OriginCF = CameraSubjectPart.CFrame * CFrame.Angles(0,math.rad(Radians))

It’s giving an error because there is only 2 arguments in CFrame.Angles so I changed it to:

local OriginCF = CameraSubjectPart.CFrame * CFrame.Angles(0,math.rad(Radians),0)

But then it was giving another error on this line saying invalid argument #1 to ‘new’ (Vector3 expected, got CFrame):

Camera.CFrame = CFrame.new(RevolvePosition, CameraSubjectPart.Position)

So I’m not sure what to do about that. I think it might be because of the values in CFrame.new because I changed it to Vector3.new and it told me to change it back to CFrame.

Oh yeah I missed a lot hold on

should be

Camera.CFrame = CFrame.new(RevolvePosition.Position, CameraSubjectPart.Position)
1 Like

Thanks, that fixed it. But, when I press the play button I change the camera back to custom like this:

Camera.CameraType = Enum.CameraType.Custom

But the camera just goes inside the CameraSubjectPart instead of the player. Is it because the CameraSubject is still set to that part? If so how would I change it to focus back on the player?

change the Camera.CameraSubject to game.Players.LocalPlayer.Character.Humanoid

3 Likes

Never mind I just had to set the CameraSubject back to the player’s humanoid when the play button was pressed. Thanks for your help.

1 Like