circular gravity

Started by
10 comments, last by Bacterius 12 years ago
Hi,

Sorry I haven't replyed in ages, I've been trying a few things out,
first off I looked into Polar coordinate systems but it seems to me like I would have to change the way everything in my code worked as position would no longer be expressed as a 2D Vector (x, y) but instead as an x value and an angle. Having read a bit about this I couldn't really see any extreme advantages this would have over the system I using at the moment so I left it alone, I would love for someone to explain some advantages and I may re-consider.

I then set about implementing my own gravity and physics which went reasonably well but I still couldn't quite get it to feel right with the rotating of objects so I got a copy of Box2D and started playing around with it. I really like it and got some cool things running so I think I will stick with this for the physics for my game as it will save me a lot of trouble having to write my own routines.

I now have a different question but since it is related I thought I would just ask it here,
In Box2D you specify the gravity vector when you create a new World, as my gravity vector will vary depending on the position of each object I need to alter how Box2D works, so I was wondering if anyone has any advice on a good way to do this or if there is an example anywhere of someone using Box2D but specifying the gravity vector using the centre point of a circle.

Thank you all for your advice, so far it has been very useful.

"To know the road ahead, ask those coming back."

Advertisement

Hi,

Sorry I haven't replyed in ages, I've been trying a few things out,
first off I looked into Polar coordinate systems but it seems to me like I would have to change the way everything in my code worked as position would no longer be expressed as a 2D Vector (x, y) but instead as an x value and an angle. Having read a bit about this I couldn't really see any extreme advantages this would have over the system I using at the moment so I left it alone, I would love for someone to explain some advantages and I may re-consider.

I then set about implementing my own gravity and physics which went reasonably well but I still couldn't quite get it to feel right with the rotating of objects so I got a copy of Box2D and started playing around with it. I really like it and got some cool things running so I think I will stick with this for the physics for my game as it will save me a lot of trouble having to write my own routines.

I now have a different question but since it is related I thought I would just ask it here,
In Box2D you specify the gravity vector when you create a new World, as my gravity vector will vary depending on the position of each object I need to alter how Box2D works, so I was wondering if anyone has any advice on a good way to do this or if there is an example anywhere of someone using Box2D but specifying the gravity vector using the centre point of a circle.

Thank you all for your advice, so far it has been very useful.

I believe you can't use the world gravity for what you need afaik (especially since the gravity forces will have different magnitudes etc...). Perhaps Box2D already has a feature like that implemented (perhaps look into magnetization) but what I would do is disable world gravity and instead iterate over all objects each logic step and apply the correct gravity force (which is trivial to do since the gravity force is just the center point of the planet minus the center of mass of the object, scaled by the object's mass * some gravitational constant - or just using the slightly more complicated gravitational formula).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

This topic is closed to new replies.

Advertisement