I created a new demo. Download it, add your own (free) PBE swc file from Pushbuttonengine.com, and test the demo!
Box2D does many things well, including support for one worldwide gravity (*everything* falls down, up, at whatever angle you want, or you can have no worldwide gravity at all.
One thing that is *NOT* natively supported is for a Box2D body to have RadialGravity (like an ‘earth’ that attracts a ‘moon’ to it) on one or more objects. But its possible to create.
I have created a demo with Box2D and Pushbutton to support this radial Gravity. My calculations are based on distance (further = less gravity) and mass (light objects are affected more by heavy objects). But, none of my calculations reflect real physics calculations. Depending on the game I may create, I will adjust it manually to ‘look good’.
USES FOR RADIAL GRAVITY
* #1 You can have 1 or more objects that ‘repel’ 1 or more objects. Or ‘attract’.
* #2 This is cool for wind/water affects on objects.
* #3 You can have planets with planetary gravity. I’ve seen some games that do this (likely hand-made math, not Box2D).
- Follow comments and add your own comments on the PushButtonEngine Forums.
- Question – In my RadialGravityComponent I have a method of _getRadialGravityComponentForB2Body (aB2Body : b2Body) : RadialGravityComponent. It works fine, but is there another way to do this more efficently?
- Question – Is there an existing way to do this within PBE, generally speaking, to get the IEntity ‘owner’ for a b2Body?
[private_Free member]Enjoy this members-only content!
- Download the PBEBox2DRadialGravity.zip Flash Builder 4.5 as3-only Project.