How do i do that? I've tried looking into a couple of scripts, But... They don't work do i need a follow script etc. Can anyone help? Thanks. Heres the link the the moon>http://www.roblox.com/Shadow-Renegade-Shadow-Station-Raid-able-place?id=153294271
I am trying to make a Moon revolve around a planet. How do i do that?
1 answer
All that is required here is some geometrical description of the movement of the moon, and an update loop/coroutine to process it.
You could describe the orbit of a planet around another, particularly in computer simulation, in various ways depending on what you intend to do with it.
I doubt you'll want to simulate the actual gravitational relationship of bodily orbits, but rather just the approximate circular movement of your moon around a planet.
So what you'll need in the script is: -A reference to to the center of rotation, the three dimensional coordinate that you want the want the moon to rotate around
-A reference to the moon object (a Part)
-A vector (Vector3 in Roblox) describing the direction of the axis about which the moon rotates: For example, if you want the moon to rotate around the planet horizontally, you need to rotate around the y-axis, which is (0,1,0) in vector form.
-The radius of orbit, i.e. how far away you want the moon to be from the planet
The following script will work if:
A) There is a Part called Orbit in the Workspace
B) There is a Part called Center in the Workspace
center = workspace.Center.Position --Coordinate Reference
body = workspace.Body --Reference to the 'moon'
axis = Vector3.new(0.25,1,0.5) --Change these numbers to change axis of rotation
radius = (body.Position - center).Magnitude --Calculates distance based on where you leave the moon in the workspace
space = CFrame.new(center,center+axis) --This is a CFrame for the coordinate space we've made
--Variables to keep track of speed and time
delta = tick()
timer = 0
multiplier = 1 --If you want it to go twice as fast, use 2, or half as fast, use 0.5, etc...
--A function to update the position of the moon
game:GetService("RunService").RenderStepped:connect(function()
--Triggers every ?1/60th of a second
delta = tick() - delta
timer = timer + delta
body.Position = space:toWorldSpace(CFrame.new(radius*math.cos(timer*multiplier),radius*math.sin(timer*multiplier),0)).p
delta = tick()
end)
Hope that helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Hmmmm... Dind't seem to work.