Is there a way to disable or enable gravity for individual objects?
[Solved]
Set global gravity to 0.
Use downward force on individual objects to replicate gravity.
The amount of force should be ( original gravity value * 0.02 ) * the object's mass.
(The "0.02" just converts C2-pixel-units to Box2D-units.)
When applying the force, specify image point "0", to use the center-of-mass.
(When applying forces, specifying image point "0" will apply to the center-of-mass, and image point "-1" will apply to the origin point set in the image editor.)
e.g. If your original global gravity was "10", then to recreate it with force on an object, you apply a force of 0.2 * the object's mass.
---- (original text continued) ----
Currently two iffy approximations come to mind, but they both have weird issues that separate them from being actual gravity.
Downward force - as gravity?
Globally disable gravity,
Then, for objects that should experience gravity, apply a downward force proportional to object mass.
This is kind of close to gravity, except that in the physics behavior I can only find actions that apply a force vector to a single point on the object. If this point is not the center of mass (or does not lie on a line through the center of mass), then the object will experience torque.
I figured there would be a way to retrieve the center of mass coords from the physics behavior, and there is, but I can't find an action in the physics behavior to apply a force on an object that uses XY cords as parameters. The only point parameter is an image point selection.
For simple symmetrical objects where the center of mass is always dead center, you can just put an image point there and use that, but it's not a generally applicable solution. By contrast the built-in global gravity will work correctly regardless of the specific shape of the collision polygons of the affected objects. I would like to use something that general if it exists.
Direct velocity manipulation?
The other option would be to directly add to the object's velocity, which has it's own issues. Framerate independence being the main one that comes to mind. Even with the incorporation of "dt" with an integration step I'd be concerned about mixing both force and velocity level alterations to the object's state, as well as mixing by-hand framerate compensation and integration (as in mathematical integral) with whatever the Box2D asm.js physics engine is doing internally to handle framerate independence and integration. I think this might also bypass friction and linear damping.
Any thoughts or suggestions are welcome. :)
(Minor update)
Image point "0" & "-1" for joints
In the Physics behavior manual page, in the "Physics actions: Joints" section, there is a mention that, for "Create distance joint" and "Create revolute joint" actions, image point "0" specifies the center of gravity instead of the origin image point, and "-1" specifies the origin image point. I don't know if this is also the case for applying forces, as nothing to that effect is mentioned for force actions. I'll test it out and report back.