Page 1 of 1

Making an object orbit around another object

Posted: Wed Oct 07, 2015 6:26 pm
by Doctory
Hello
Lets say I have 2 circles
I want 1 of those circles to orbit around the other
How would I do this? Is there a formula?

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 6:48 pm
by bobbyjones
Do you want an actual orbit or just an object following a circle path?

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 6:48 pm
by Doctory
Could you provide both?

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 7:33 pm
by Taz
To rotate an object around an other object, you can use math.sin and math.cos for it. Heres an example:

Code: Select all

angle 	   = angle + 1*dt 
distance    = 100

local new_x = object.position_x + math.sin(angle) * distance
local new_y = object.position_y + math.cos(angle) * distance

--now apply new_x and new_y for the object that should rotate around the other object

Hope this helps a bit.

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 8:43 pm
by bobbyjones
Well that is not an orbit that is to make an object follow a circular path. Making a true representation of an orbit it would require googling of how an orbit work and probably not look like how you would want. I tried a true orbit once. I gave up :( lol

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 9:25 pm
by Taz
bobbyjones wrote:Well that is not an orbit that is to make an object follow a circular path. Making a true representation of an orbit it would require googling of how an orbit work and probably not look like how you would want. I tried a true orbit once. I gave up :( lol
Well I know, but he asked also for a circular path :). Only wanted to show a basic example for it.
Sad to hear :( but math can sometimes be pretty complicated.

Re: Making an object orbit around another object

Posted: Wed Oct 07, 2015 9:30 pm
by MadByte
here is a orbiting project I've seen some time ago