This project has moved and is read-only. For the latest updates, please go here.

Farseer 3.0 questions [Beginner]

Aug 11, 2010 at 5:29 AM
Edited Aug 11, 2010 at 7:31 AM

Recently I've been switching to Farseer 3.0 from 2.1 and now I'm facing some problems which I don't really know what happens.

So basically what I want to try is moving a box shape object.


// First I have created world with gravity
World world = new World(new Vector2 (0.0f, 920.0f);

// Then I start to create my box object
Vertices box = PolygonTools.CreateRectangle(50, 50);
PolygonShape boxShape = new PolygonShape(box);

boxBody = BodyFactory.CreateBody(World);
boxBody.Position = new Vector2 (400, 100);
boxBody.BodyType = BodyType.Dynamic;

boxBody.CreateFixture(boxShape, 1.0f);

// I did update the world in Update() 
World.Step(gameTime.ElapsedGameTime.Milliseconds / 1000.0f);

// This is the control that I used to move the object
if (keyboardState.IsKeyDown(Keys.W))
    boxBody.ApplyForce(new Vector2(0.0f, -1000));
// Draw the box
spriteBatch.Draw(boxTexture, boxBody.Position, null, Color.White, boxBody.Rotation, boxOrigin, new Vector2(1.0f, 1.0f),
                SpriteEffects.None, 0.5f);


So my problem now is, when I press W, the object won't move. It seems like the object didnt react to the force applied.

But the weird thing is, the object did react to the gravity of the world, it will slowly falling down.

Anyone knows where's the problem is?

Aug 11, 2010 at 2:36 PM
In FPE 3.0 we use the MKS (Meter-Kilo-Second) system and thus, your values need to be much smaller. We no longer operate on pixels. Your rectangle in the eyes of the physics engine is 50x50 meters, that is huge. However, your problem might be the timestep. Try using something like: gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f
Aug 11, 2010 at 2:54 PM
Edited Aug 11, 2010 at 2:55 PM

The polygon create rectangle I'm gonna replace it with myTexture.Width and myTexture.Height because is it need to be fit with my texture size?

Actually what is the proper way of declaring a physics object in Farseer 3.0? I have look through the testbed but I don't really get it.

in Farseer 2.0, the steps would be:

1. Declares body

2. Declares geom

But in Farseer 3.0, I've found out which I don't understand is

1. Declares body

2. Declares fixture

During the declaration of fixture, I actually have two options: 

1. FixtureFactory and create a fixture, but after I create a fixture, how should I attach it to the body since Body.CreateFixture() accept shape as the parameter.

2. Declares PolygonShape, then use Body.CreateFixture(shape)

Which is the correct way should I use?

Aug 13, 2010 at 11:13 PM
In FPE 3.0, a fixture is what holds a body and shape together. Once you create a fixture with the FixtureFactory, you already have a body inside the fixture. No need to create one yourself.

Another way of doing it is what you describe in point 2: Create PolygonShape then use Body.CreateFixture(shape) (granted you already have created the body). This is the same as using the FixtureFactory.

Both ways are fine - I would go with the factory since it clutter less and is easier for me to use.

As for the Width and Height of the texture, you need to scale your physics objects to fit in size or even better, learn how to use view and projection matrix. There is also a good thread about how to create a camera here on the forums. You can find it here:
Aug 16, 2010 at 3:18 PM

I'm posting this here, not because it's relevant to the original post, but because it fits the subject. This is most probably a beginner question.

I have been trying to implement the FixedAngleSpring example as part of an ongoing integration with TorqueX.  I need to understand the moving parts. It seems that there are 2 bodies involved.  The circle portion in the example and the flexible rectangle.

I read this in the docs on the description here:

The white element in the middle functions just like a springboard. The angle spring is of fixed type. This means that it's attached to the "world". A revolute joint is used to pin the spring board to the world so that it stays in the same position, but still allow it to rotate around the pivot point.

So how many bodies, geoms, joints, and springs must come together to make this happen?

It looks like the circle is one body with a fixed revolute joint attached. This would allow it to spin 360 degrees while remaining fixed. I don't know if this body needs a geom.

It looks like the rectangle is a separate body (and appears to have a geom as well).

After this, things get hazy.  I don't know how/if the rectangle body attaches to the circular body. Is this another revolute joint? Is it anchored at the left edge of the rectangle? Also the spring is fixed, but I don't know how to set its anchor position.  Even though the docs say the springs have an Anchor1 and Anchor2 property, they don't appear to actually have one. If they do, its under a different name, and for the fixed angle spring, I couldn't figure it out.

Any help would be appreciated...