PBox2D/JBox2D Tricks

This is a list of useful stuff I’ve put together while learning the PBox2D/JBox2D library. This is a great 2D physics engine that was ported from Box2D to Java and then was wrapped for easy use in Processing by Daniel Shiffman. I will update this from time to time so it’s current state is not the final state.Please note that most of these tricks will require a basic level of understanding of the Box2D engine.

Using a DistanceJoint to connect an object to a specific anchor point on another object.

This one requires that you know how to set up a joint between two objects. The usefulness of this trick is being able to specify a custom anchor point. I apologize for the messyness of this one; I grabbed pieces of it from a program I wrote.

DistanceJointDef djd = new DistanceJointDef();

// basic settings for this joint.

Vec2 jointPos = …  // Engine World offset from the center of the body

Vec2 offset = new Vec2( body.getWorldCenter().x, body.getWorldCenter().y );
offset.x += jointPos.x;
offset.y += jointPos.y;

djd.initialize( body1, body2,



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: