Radial gravity

Just wondering if anyone knows how to produce radial, or circular, gravity. Could also be used to simulate magnetism, I guess.

Basically, I’d like everything in my game (concept right now) to gravitate towards the centre (or other arbitrary point, or points) like a black hole or something.

I’m guessing this isn’t a simple function of the physics engine which can be employed - but would it be best to implement it using something like really weak touch joints; absolutely positioning with some complex maths; mucking about with the gravity settings; or something with linear force?

Any ideas/sample code peeps?

Matt. [import]uid: 8271 topic_id: 4290 reply_id: 304290[/import]

You could use Particle Candy… [import]uid: 9371 topic_id: 4290 reply_id: 13329[/import]

Can the field fx be applied to objects which have not been created using PC?

m [import]uid: 8271 topic_id: 4290 reply_id: 13332[/import]

In my game I’m mixing native physics with my own manual “physics”, and part of that is a general “followTarget” routine. Basically when a targetSprite is set then the sprite in question will follow its x and y coordinates by adjusting its own speed, depending on where the sprite is in relation to the targetSprite (I’m currently only using followTarget for my non-physics sprites, where I have manual speed code, but you could probably either adjust x and y coordinates all the same on physics objects, or adjust their linear force by giving them pushes). Not sure if that would work for you, i.e. by putting the targetSprite on your black hole. Keep us updated on what you come up with!

Perhaps a general “magnetic” value for physics object could come in handy, e.g. a negative value could blow things close-by away for explosions and stuff… [import]uid: 10284 topic_id: 4290 reply_id: 13847[/import]

Thanks; I actually came up with a solution which essentially applies force in a given direction based on the effect I want to acquire: https://developer.anscamobile.com/forum/2010/12/09/gravitymagnet-elastic

Matt. [import]uid: 8271 topic_id: 4290 reply_id: 13849[/import]

There is a tutorial available for this now:

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

Yes :wink:

There is a tutorial available for this now:

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

Yes :wink: