box2dgame-physicschipmunk

Scaling Physics World


I'm currently working on a 2D physics abstraction layer that can use Box2D or Chipmunk2D as physics engine. I initially used Chipmunk2D and am now implementing Box2D. One of the issues I ran into was the maximum speed of Box2D (as defined by b2_maxTranslation). To solve this issue I've decided to scale the world so it fits better with Box2D units.

Currently I'm scaling down with a constant factor:

As I'm using densities to define the fixtures, this would also scale down the body masses.

What I've noticed is, this does not work. Whenever I apply a force the body moves much faster than when the scale is high.

Is there something else I need to scale to make the bodies update correctly or should I scale the impulses and forces in some other way?


Solution

  • Given a scale X that scales the geometry, I ended up doing the following (I didn't bother scaling the damping effect):

    Velocity (SetLinearVelocity) - Linear

    Force (ApplyForce) - Cubic

    Position (any fixture def CreateFixture) - Linear

    Mass (GetMass) - Square

    Gravity (SetGravity) - Linear

    Impulse resolving (PostSolve WorldManifold.normal) - Cubic inverse

    Where

    I did several tests with these factors and they seemed to work fine in preserving angular velocities as well as linear movement (I did try several others that failed just this). See https://bitbucket.org/Kipt88/polymorph/src/b4d29e2434a2ed1eda2183f9e16f4782c40ee026/modules/physics2d/files/source/box2d/?at=master for reference (source code no longer maintained).