Could be a rounding error caused by a wrong variable type, or incorrect angle calculation.
I set up a demo code which orbits earth around the sun and the moon around earth, using simple sin/cos calculations. Maybe you can locate your bug by having a look at it
#option_explicit
SetWindowTitle( "Orbits" )
SetVirtualResolution ( 1024, 768 )
SetSyncRate ( 60, 1 )
#constant EARTHDISTANCE = 300
#constant MOONDISTANCE = 70
global sunx as float = 512.0
global sunz as float = 384.0
global earthx as float
global earthz as float
global moonx as float
global moonz as float
global earthangle as float
global moonangle as float
repeat
earthangle = fmod ( earthangle + 0.5, 360.0 )
moonangle = fmod ( moonangle + 1.5, 360.0 )
earthx = sunx + cos ( earthangle ) * EARTHDISTANCE
earthz = sunz + sin ( earthangle ) * EARTHDISTANCE
moonx = earthx + cos ( moonangle ) * MOONDISTANCE
moonz = earthz + sin ( moonangle ) * MOONDISTANCE
DrawEllipse ( sunx, sunz, 45, 45, MakeColor ( 255, 0, 0 ), MakeColor ( 255, 255, 0 ), 1 )
DrawEllipse ( earthx, earthz, 20, 20, MakeColor ( 0, 0, 255 ), MakeColor ( 0, 255, 255 ), 1 )
DrawEllipse ( moonx, moonz, 8, 8, MakeColor ( 255, 255, 255 ), MakeColor ( 100, 100, 100 ), 1 )
Sync()
until GetRawKeyPressed ( 57 ) or getrawkeypressed ( 27 )
end
Cheers,
PSY