✓ Accepted answer
I have recreated the wiki code to help explain how CFrames work. This is my base example which is a local script in StarterCharacterScripts.
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local offsetCFrame = CFrame.new(0, 10, 30)
while true do
for i=1, 360 do
local tmpCF = CFrame.new(rootPart.Position)
tmpCF = tmpCF * CFrame.Angles(0, math.rad(i), 0)
tmpCF = tmpCF * offsetCFrame
camera.CFrame = tmpCF
runServ.RenderStepped:Wait()
end
end
The steps take in this code for the camera are:-
- Start at player Vector3
- Rotate to the CFrame by the current degrees
- Offset to world space
As this is the end position you can create a new CFrame using the constructor CFrame.new(position Vector3, lookAt Vector3) if you wanted to make a CFrame looking back at the player.
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local offsetCFrame = CFrame.new(0, 10, 30)
while true do
for i=1, 360 do
local tmpCF = CFrame.new(rootPart.Position)
tmpCF = tmpCF * CFrame.Angles(0, math.rad(i), 0)
tmpCF = tmpCF * offsetCFrame
camera.CFrame = CFrame.new(tmpCF.p, rootPart.Position)
runServ.RenderStepped:Wait()
end
end
Some maths fun using sin :3
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local offsetCFrame = CFrame.new(0, 10, 30)
while true do
for i=1, 360 do
local tmpCF = CFrame.new(rootPart.Position)
tmpCF = tmpCF * CFrame.Angles(0, math.rad(i), 0)
tmpCF = tmpCF * CFrame.new(0, (math.sin(math.rad(i))) * 2 + 2, 30)
camera.CFrame = CFrame.new(tmpCF.p, rootPart.Position)
runServ.RenderStepped:Wait()
end
end
I hope this helps
2 comments
Are you asking for the camera to orbit around the player and have it look at them?
Yes