Dynamic Body Types and Static Body Types

Technorati Tags: ,,,

In Box2D ( Farseer) you can create Dynamic and Static Body Types. This is not to be confused with the isStatic property, the isStatic property is for an object which does not move, you use this property for Static obstacles in a game.

A Dynamic Body  Type is an object which can for example have objects attached to it. In my game Boo Boo Birds you anchor bomb blades to the player bird . On declaring the player bird set it to dynamic

body.BodyType = BodyType.Dynamic;


To link another object to this object when it for example collides with the object then do the following

agent.currRopeJoint = new RopeJoint(fixtureA.Body, fixtureB.Body, ConvertUnits.ToSimUnits(fixtureA.Body.Position), ConvertUnits.ToSimUnits(fixtureB.Body.Position));
agent.currRopeJoint.MaxLength = 0.4f;
agent.currRopeJoint.CollideConnected = false;

agent.currFixture = fixtureA;
agent.myFixture = fixtureB;

Then to remove the object so that it drops to the ground

if (currRopeJoint != null)
                      currRopeJoint = null;
                      bvertset = false;

You can vary the distance the object is connected to the other object by changing a parameter. It is also advisabe to ensure the the NotCollides parameter is set to each object so it does not collide with the object it is attached to.

This has been done earlier on with the following statement in the first example of the code



Tags: , , ,

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: