Keeping bodies at a given distance – distance joints

A distance joint is probably the easiest joint to understand and handle. It just sets the distance between two points of two objects, and it will remain constant, no matter what happens.

So we are about to create a new box and link it with the distance joint to the one already in the world. Time to change a bit in our Main function:

public function Main() { world=new b2World(new b2Vec2(0,9.81),true); debugDraw(); var bodyDef:b2BodyDef=new b2BodyDef(); bodyDef.position.Set(320/worldScale,470/worldScale); var polygonShape:b2PolygonShape=new b2PolygonShape(); polygonShape.SetAsBox(320/worldScale,10/worldScale); var fixtureDef:b2FixtureDef=new b2FixtureDef(); fixtureDef.shape=polygonShape; var groundBody:b2Body=world.CreateBody(bodyDef); ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.