Making an object orbit around another object

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Making an object orbit around another object

Post 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?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Making an object orbit around another object

Post by bobbyjones »

Do you want an actual orbit or just an object following a circle path?
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Making an object orbit around another object

Post by Doctory »

Could you provide both?
User avatar
Taz
Prole
Posts: 11
Joined: Tue Feb 12, 2013 3:36 pm

Re: Making an object orbit around another object

Post 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.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Making an object orbit around another object

Post 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
User avatar
Taz
Prole
Posts: 11
Joined: Tue Feb 12, 2013 3:36 pm

Re: Making an object orbit around another object

Post 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.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Making an object orbit around another object

Post by MadByte »

here is a orbiting project I've seen some time ago
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests