# How To Make The Earth Visible Realistically?

I’m working on the 3D atmosphere script. The goal of this project is to simulate the realistic space. It is almost done, but there is one problem that I tried to solve and always failed. What I’m struggling with is replicating the earth scale in different distances.

I looked around the forum for a topic similar to this and I couldn’t find any. I don’t think this topic is common to many developers so I created one by myself. I know it will use lot of math knowledge to do this, but I don’t know how to make it work properly.

So, I made a replica of earth scale for comparison. This will help me matching the earth from script with a replica. This scale represents to 100,000 studs. Very big, isn’t it? I also made a dome to replicate the Roblox world render distance. According to that, it is 100,000 studs maximum.

How It Works :
The earth follows the camera’s height. Then, it will shrink down and move closer. That’s because it can’t be out of the render distance. It must be at the lowest point of the render distance too so it won’t be weird when an object go through.

This is the problem I’m having. The earth shrinks faster as my camera gets higher and it is out of the dome which means it is also out of the Roblox render distance.

https://cdn.discordapp.com/attachments/799943430314393630/883374737034715176/Action_9-3-2021_10-31-39_PM.mp4

Here’s the test script.

``````local camera = workspace.CurrentCamera
local earth = workspace.Atmosphere.Earth
local dome = workspace.Atmosphere.Dome -- This dome represents to Roblox render distance (100k studs max)
local baseScale = workspace.Atmosphere.Scale -- This is for scale

local scale = 0
local distance = 0
--[[ scale / distance I've replicated
100 km = 0.9845 / 1
1,000 km = 0.3897 / 4.5
10,000 km = 0.084 / 1.5
100,000 = 0.01291 / 1.05
1,0000,000 = 0.001365 / 1.005
]]
game:GetService("RunService").RenderStepped:Connect(function()
------------------------------------------------------------------------------------------------------
scale = 1 - (0.0043055555 * camera.CFrame.Position.Y) -- only work within 100km
distance = 1 + (camera.CFrame.Position.Y * 0.001) -- this follows the camera's height
------------------------------------------------------------------------------------------------------
local size = 2.294 * scale
local altitude = -229.4 + (camera.CFrame.Position.Y * distance)
earth.Position = Vector3.new(camera.CFrame.Position.X, altitude, camera.CFrame.Position.Z)
earth.Mesh.Scale = Vector3.new(size, size, size)
------------------------------------------------------------------------------------------------------
dome.Position = camera.CFrame.Position
baseScale.Position = Vector3.new(camera.CFrame.Position.X, -229.4, camera.CFrame.Position.Z)
end)
``````

You can try it out here. Look in a Gui for the script called “Earth_Script”.
Earth Demo.rbxl (34.8 KB)

Let me know if you can figure it out. It will help me and my project a lot if this can be solved easily. Thanks in advance!

1 Like

For the earth not being within roblox’s render distance, could you not set the CameraSubject to the earth? Or instead, create a part between both the camera and the earth and set that to be the CameraSubject?

The earth is very big and I don’t think you can see that if the CameraSubject is set to it. The camera is an example of player flying a spacecraft above the earth and it won’t always point down like that. This is something like what Pulsarnova’s Space Sailors has. I know there is a free script of it, but I want to make my own so I can customize it too.