How to make a gravitational pull on an object?

Ok so i have a red circle and a blue circle 

So the red circle is spinning and i want the blue circle to be stuck the side of that circle and just spin with the red circle…

While the red circle is spinning and the blue circle is stuck to the red one; you can touch the screen and the up but gets pulled back by the gravitational pull of the red circle…

Here i wrote the code of the red and blue circles and the red circle spinning…

I just can get the blue circle to stick to the red one and then make a gravitational pull for the red one…

THIS IS SAMPLE CODE… YOU CAN PUT THIS IN A MAIN.LUA

local physics = require("physics") physics.start() local spinner = display.newCircle( 0, 0, 50 ) spinner.x = display.contentCenterX spinner.y = display.contentCenterY spinner:setFillColor( 1, 0, 0 ) physics.addBody( spinner, "static", { bounce = 0 }) local player = display.newCircle( 0, 0, 25 ) player.x = display.contentCenterX player.y = display.contentCenterY - 200 player:setFillColor( 0, 0, 1 ) physics.addBody( player, "dynamic", { bounce = 0} ) local doTurn = function(event) spinner.rotation = spinner.rotation + 15 end Runtime:addEventListener( "enterFrame", doTurn )

Thanks to anyone who can help!

I think you want to search the forums a bit, this question has been asked many, many times.

It’s also quite a fun one to think about and solve yourself. There are many ways to do it, too.

You can try thinking about how one object might attract another, either with joints or by affecting the direction of movement. You can try applying force against one object, as well.

Yes ive searched everywhere and tried things i cant seem to get it to work… Maybe cause ive had less than 12 hours of sleep in the past 3 days but oh well haha … maybe there are some examples you may know of??

Try searching for the term radial gravity (ex: Google _ radial gravity corona _).

Here is one very useful hit from that search:

https://coronalabs.com/blog/2013/04/09/physics-radial-gravity-and-predicting-trajectory/

Also, we’ve been talking about this for many episodes now (starting with hangout 154):

http://coronageek.com/2151/corona-geek-154/

http://www.youtube.com/watch?v=6yFGry7Hpyc&t=0m21s

Here is the code:

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/ICanMakeThat/TheyNeedToBeFed.zip

I’ve made some tutorial posts in the past, linked from my blog:

http://springboardpillow.blogspot.co.uk/search/label/corona

@SonicX278, can we respectfully request that you not use larger fonts, bolding, etc. of your entire text please. It violates forum rules.

https://coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/

See Rule #12. I know sometimes copy/paste maintains formatting from other pages/programs. You can use the “eraser” icon (top row, second from left) to clear formatting.

Rob

Oh wow haha didn’t know that … Sorry though won’t happen again. :slight_smile:

I think you want to search the forums a bit, this question has been asked many, many times.

It’s also quite a fun one to think about and solve yourself. There are many ways to do it, too.

You can try thinking about how one object might attract another, either with joints or by affecting the direction of movement. You can try applying force against one object, as well.

Yes ive searched everywhere and tried things i cant seem to get it to work… Maybe cause ive had less than 12 hours of sleep in the past 3 days but oh well haha … maybe there are some examples you may know of??

Try searching for the term radial gravity (ex: Google _ radial gravity corona _).

Here is one very useful hit from that search:

https://coronalabs.com/blog/2013/04/09/physics-radial-gravity-and-predicting-trajectory/

Also, we’ve been talking about this for many episodes now (starting with hangout 154):

http://coronageek.com/2151/corona-geek-154/

http://www.youtube.com/watch?v=6yFGry7Hpyc&t=0m21s

Here is the code:

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/ICanMakeThat/TheyNeedToBeFed.zip

I’ve made some tutorial posts in the past, linked from my blog:

http://springboardpillow.blogspot.co.uk/search/label/corona

@SonicX278, can we respectfully request that you not use larger fonts, bolding, etc. of your entire text please. It violates forum rules.

https://coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/

See Rule #12. I know sometimes copy/paste maintains formatting from other pages/programs. You can use the “eraser” icon (top row, second from left) to clear formatting.

Rob

Oh wow haha didn’t know that … Sorry though won’t happen again. :slight_smile: