Rotating camera around map

I am making an intro UI and I want it to circle above the city in the sky, I know that I will tween the camera, I just don’t understand how I will make it go in a circle. Help would be loved.

Maybe RodConstraint a part that will rotate 360 degrees and attach it to the camera? I think that’s how RodConstarints work.

What I’m trying to say is I don’t understand the maths involved in calculating the info for the tween xD

I had actually written a function that does this.

-- in a module
local function get_cframe_around_pivot(pivot: CFrame, angle: number, offset: CFrame): CFrame
    return pivot*CFrame.Angles(0, math.rad(angle), 0)*offset
end

return get_cframe_around_pivot

Just some example code

local part = Instance.new("Part")
part.Parent = workspace

local RunService = game:GetService("RunService")

local DISTANCE = CFrame.new(0, 0, -10)

for i = 0, 360 do
    workspace.CurrentCamera.CFrame = get_cframe_around_pivot(part.CFrame, i, DISTANCE)
    RunService.RenderStepped:Wait()
end

This will turn the camera a full 360 degrees around the part from a 10 stud distance

8 Likes
I also created a script that does this. Try this out.

-- Rotate camera around model
local Offset = CFrame.new(0, 10, 30)
local TargetOffset = Vector3.new(0, 0, 0)
local TargetPos = ROTATE_AROUND_PART.Position + TargetOffset
local A = 0
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function(Tick)
	A = A + Speed * Tick
	Camera.CFrame = CFrame.new((CFrame.new(TargetPos)
					* CFrame.Angles(0, math.rad(A), 0)
					* Offset).Position, TargetPos)
end)
6 Likes

I now owe you my life and I am grateful to your service

1 Like

May I know why did you put : in the function’s parameter? Does it mean something?

also would like to ask would this be how I write it in the module? Im not that experienced with modules

local module = {}

local function get_cframe_around_pivot(pivot: CFrame, angle: number, offset: CFrame): CFrame
	return pivot*CFrame.Angles(0, math.rad(angle), 0)*offset
end

return get_cframe_around_pivot

Its just a type annotation, a way of telling the type checker what kind of variable that will be, in strict mode.

1 Like

You don’t need the first variable declaration. The code I posted is fine alone.

1 Like

Sorry I’d hate to annoy you, it appears to not be working for me

Here is what I have:

cam.CameraType = "Scriptable"

spawn(function()
	while screen.Parent.Enabled == true do
		local distance = Vector3.new(-100,0,0)
		for i = 0, 360 do
			cam.CFrame = circlemod.get_cframe_around_pivot(workspace.TargetBlock.CFrame, i, distance)
		end
	end
end)

and this is the error I get

 ERROR:Players.AdanTalaz.PlayerGui.FadeGui.Code.Client:38: attempt to index function with 'get_cframe_around_pivot' - Players.AdanTalaz.PlayerGui.FadeGui.Code.Client, line 38

That means circlemod points to a function. Try making get_cframe_around_pivot a standalone function.

Yes, however that function is inside a module called “circlemod” and this is in a local script

Could you try posting the full code, im not really understanding