How would i make a camera that follows a planet? [SOLVED]

Hello, So I have made a solar system game I have been trying to make/fix this issue for a while okay so what I’m trying to do is make the camera (player’s view) able to view and follow the moving planet (Part) I have already made the camera but couldn’t figure out how the camera would keep following the planet as it moves i’ve tried making the camera have the same movement as the planet (part) but it still wouldn’t work here’s the script that allows the planet(part) to move

x = 90

while true do

wait(0.05)

script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi/x, 0)

end 

this is what a planet looks like
image

i’ve tried adding the script of the rotation into the camera but it sill wouldn’t work how can i fix this?

Summary: How to make camera follow planet part?

local planet = -- path to ur planet
local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable
while task.wait() do
	local startpoint = planet.Position + Vector3.new(0,planet.Size.Y,planet.Size.Z)
	camera.CFrame = CFrame.new(startpoint,planet.Position)
end
1 Like

You should use RunService over wait loops.

local RunService = game:GetService("RunService")

local camera = workspace:WaitForChilds("Camera")
local planet = -- path to ur planet

camera.CameraType = Enum.CameraType.Scriptable

RunService.RenderStepped:Connect(function()
	local startpoint = planet.Position + Vector3.new(0,planet.Size.Y,planet.Size.Z)
	camera.CFrame = CFrame.new(startpoint,planet.Position)
end)
1 Like

yea but task.wait == runservice.heartbeat

1 Like

You should not be using heartbeat for camera manipulation

who said that? I dont think that there is any problem using heartbeat in cam manipulation

You should use it because it’s immediate for the player, and even roblox manipulates camera on RenderStepped.

1 Like

why not just put CameraSubject to the planet?
it makes the camera follow planet but also let you rotate and see the planet,zoom in and out too

2 Likes

ehhhhhhhhh meh then i guess just use it lol ¯\_(ツ)_/¯

Where should this be located it doesn’t seem to work? this goes for @TheZanderius post as well

in a local script some where in starter gui

Ok so what you would want to do, is make a remoteEvent in ReplicatedStorage, and then when you want the planets to start orbitting you fire it from server. Then you receive it on the client and you run the code. You want the receiver code to be in StarterPlayerScripts.

1 Like

Or if you want it to always be spinning, you just make a the script (a local script) in StarterPlayerScripts without dependency from the remoteEvent

I think Creeperman16487 have the best way to do what R00t want no ? :thinking::face_with_raised_eyebrow:

1 Like

This does work but the problem is doesn’t work on the plants it just makes the camera position diffrent and sticks it as that

How would i do that?? and does it need a script?

then check out the other replies

What do you mean it doesnt work on the planets, if you want a camera system that you can zoom in and out for, you should use CameraSubject

1 Like

i made a script and it works

cam = workspace.CurrentCamera
cam.CameraSubject = game.Workspace["Solar System"].Terrestrials.Mercury

But how would i make it able to switch camera subjects using gui buttons?

How do you want the user to be able to switch between planets, by timer?