Making the camera orbit around an area using BindToRenderStep?

Hello!

I was wondering how I would make my camera orbit around an area instead of making the camera rotate on a single axis?

Basically, I have this island, and was wondering how I would make the camera orbit around it, preferably similarly to the path in the following image:

Seems easy enough using TweenService, however I want to use BindToRenderStep instead of TweenService, so is it possible?

I was thinking of using a HingeConstraint and then just set the camera to a welded part, but I’m worried about exploiters being able to manipulate it.

3 Likes

Decided to think out of the box and make a spinner, put put it into ReplicatedStorage, and then the client could then clone it then, parent it to workspace. Then, after each RenderStep, it would set the camera’s CFrame to a part welded to the spinner, with whatever offset I want.

Here’s the script, feel free to use if you want (excuse the horrid indenting, devforum hates scripts for some reason):

local RunService = game:GetService('RunService')

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local chr = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

repeat wait() until chr:FindFirstChild('Head')

local CC = workspace:WaitForChild('Camera')

CC.CameraType = Enum.CameraType.Scriptable

Instance.new('BlurEffect', CC)

CC.CFrame = CFrame.new() * CFrame.Angles(0, 0, 0)

local CameraAsset = ReplicatedStorage.Assets.CameraSpinnerLocal:Clone()

CameraAsset.Parent = workspace

function rotateCamera()

    CC.CFrame = CameraAsset.CameraLocation.CFrame * CFrame.Angles(math.rad(22.5), math.rad(180), 0)

end

RunService:BindToRenderStep('CameraRotation', Enum.RenderPriority.Camera.Value + 1, rotateCamera)
1 Like

Interesting solution, but there is a simpler solution using pure CFrames.

local RunService = game:GetService('RunService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local localCharacter = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
repeat wait() until localCharacter:FindFirstChild('Head')

local camera = workspace:WaitForChild('Camera')
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new() * CFrame.Angles(0, 0, 0)
Instance.new('BlurEffect', camera)


local centerCFrame = CFrame.new(0,20,0) -- center of the rotation
local offsetCFrame = CFrame.new(0,0,50) -- 50 stud radius (moves it backwards)

local currentAngle = 0 -- in degrees

function rotateCamera()
    camera.CFrame = centerCFrame*CFrame.Angles(0,math.rad(currentAngle),0)*offsetCFrame
    currentAngle = currentAngle + 1
end

RunService:BindToRenderStep('CameraRotation', Enum.RenderPriority.Camera.Value + 1, rotateCamera)

EDIT: Better explanation.

Using CFrames, I first move the camera to the center position. I then rotate it x amount of degrees. Finally, I move it backwards 50 studs. If you want the camera to look down, you would add another CFrame.Angles at the end with a rotation to make it look down a bit.

14 Likes

Yeah, that’s definitely better than mine lol.

Thanks! Will be using that to limit the part count (3 isn’t a lot but it adds up)

I’m still a little confused on how to make the camera look down?

got the same problem, adding angle to CFrame.Angles changes the path of orbit

add

local tilt = -30
camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(tilt),0,0)

after camera.CFrame = centerCFrame*CFrame.Angles(0,math.rad(currentAngle),0)*offsetCFrame

1 Like