Oh I see what happened. I made a couple mistakes.
I will get back to you later today. I’m not home and I want to test my answer before I submit.
Oh I see what happened. I made a couple mistakes.
I will get back to you later today. I’m not home and I want to test my answer before I submit.
Okay so I made a couple of mistakes:
local dist = 60 --how far the planet is from the star in studs
local spd = math.rad(360)/10 --where 10 is how many seconds per orbit
local xangle, yangle = 0, 0 --how the planet is tilted in its orbit x/y axis
local orbitparent = script.Parent.Parent.Sun
local lastTimeLogged, count = os.time(), 0
while task.wait() do
if os.time() > lastTimeLogged then --if its been 1 second, restart count at 0
count = 0
lastTimeLogged = os.time()
end
count += 1
script.Parent.CFrame = orbitparent.CFrame*CFrame.fromEulerAnglesXYZ(xangle,((lastTimeLogged%1000)+(count/60))*spd,yangle)*CFrame.new(0,0,dist)
--lastTimeLogged%1000 <- gets us the last 4 integers of os.time(); gives us 1/10000 of accuracy between all servers planetary positions
--for greater accuracy especially at very long orbits, you could increase this to 5+
--count/60 <- this tells us how many 1/60 of a second have passed since the last second; in my tests this was extremely reliable
end
I’ve tested this code, if you have any issues let me know!
Hey your code is working! thx for the code.Seems like the yangle variable makes the planet tilt axis like earth? and also how would i add spin to the planets? i tried CFrame.Angles and didnt work
I don’t know what you mean by this, please explain
CFrame.Angles is definitely a step in the right direction. You will need to incorporate the same kind of equation we did for the orbit, for the angle.
I got excited, because one day I want to make a space game; so I’ve already went ahead and made an example of using the above code to add multiple planets in orbit, as well as, the sun has an orbit, and all of the planets and the sun have angular rotation. (the largest cube in the center is the “sun”, each consecutively smaller body is a “planet”, and they all have unique sizes, rotational speeds, and orbiting speeds); the speeds are made using a formula, so there is some symmetry that you may notice. Since I used our equation to incorporate os.time(), all of this should be synchronized between any and all servers within a very small margin of error.
i meant like this File:Earth tilt animation.gif - Wikimedia Commons
as you can see the gif that the earth is tilted and i want to do that and also the earth spins around which makes day/night
wow that looks cool… would you mind sharing the fomula of the speeds? its not a problem if you dont want
I just sent you the file.
Ah, yes… I see. The X axis is at a static angle and the Y axis is rotating slowly. You should be able to do this once you take a look at that file and try to understand everything in it. Good luck!