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.
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!