I’m making a 3D atmosphere script. It works like @Pulsarnova’s 3D atmosphere script. My current goal is to make it rotate to simulate that we’re orbiting around the earth, by using world space orientation from camera position (only X and Z). It is a fake earth to trick your eyes like you’re moving above the globe when you’re actually moving on a flat plane. I don’t use linear or angular velocity because that won’t get a proper position of the earth and it can mess up easily when a player freezes or teleports.
This is how it works.
Example by Pulsarnova’s earth script
https://cdn.discordapp.com/attachments/808543204893917264/851377654367780874/Action_6-6-2021_3-52-54_PM.mp4
See how it rotates by X and Z linear velocity. For my version, I want to use position movement instead of
linear or angular velocity.
The problem is, I don’t know how to make it rotate by using world space instead of local. You can see a video below for the issue. X orientation (red) is rotating fine, but when Z orientation (blue) tilts to 90ish degrees, it turns into Y orientation and rotates in wrong direction.
So, the main problem is Z orientation is not rotating properly after X rotates to 90ish degrees. Notice the difference at 0:09 and 0:22.
Here’s my earth rotation example script. Put it in ReplicatedFirst.
Earth Example.rbxm (16.6 KB)
Also here’s the code if you would like to mess around.
local planet = -- Your planet inside this local script
planet.Parent = workspace
local camera = workspace.CurrentCamera
game:GetService("RunService").RenderStepped:Connect(function()
local altitude = (camera.CFrame.Position.Y*0.1)
local xPosition = camera.CFrame.Position.X
local zPosition = -camera.CFrame.Position.Z
planet.Orientation = Vector3.new(zPosition, 0, xPosition)
planet.Position = Vector3.new(camera.CFrame.Position.X, altitude, camera.CFrame.Position.Z)
end)
I’ve been searching for other forums and none of them worked for me. I asked my friend for help and it didn’t work either.
Let me know if you find a solution. Thanks in advance!