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

Creating object and immidiatly setting a velocity has no effect

Jan 18, 2011 at 7:19 PM


this way I create a circle:

fixture = FixtureFactory.CreateCircle(manager.getWorld(), radius, density, position);
fixture.Body.BodyType = BodyType.Dynamic;

And now I want it to have an initial speed, first try:
fixture.Body.LinearVelocity = Vector2.UnitX * 100.0f;

-> No effect, the body is just falling to the ground

Next try:

fixture.Body.ApplyLinearImpulse(Vector2.UnitX * 100.0f, Vector2.Zero);

-> The circle just spins like hell, no linear movement

Next try:

fixture.Body.ApplyLinearImpulse(Vector2.UnitX * 100.0f, fixture.Body.GetWorldVector(Vector2.Zero));

-> Visually the same effect as before.

What am I doing wrong?

Jan 18, 2011 at 8:26 PM

Have you scaled your units to the MKS (meters kilos seconds) system (just search MKS on the discussion boards for details)?

100.0 seems like an awful lot of force to me and if you have not scaled your units, normally weird behaviour is just around the corner.

The rest looks good I guess :/

Jan 18, 2011 at 8:37 PM


thanks for the reply.

I haven't scaled anything and just tried with 1.0f instead of 100.0f. Same effect. :/

The version I'm using is 3.0 (as I'm using XNA 3.1), was there a bug in this version according to this problem?

Jan 18, 2011 at 9:58 PM

It is not enough to just change the force. That has of course no effect. I meant you have to scale everything. You did not post any of you units you use for creating that circle fixture. But make sure physics objects are between 0.1 and 10.0 units in size. Farseer 2.x used pixels as unit. That changed in 3.0 therefore you have to scale you drawing code to adapt to the smaler physics objects sizes. Have a look at the newest HelloWorldXNA sample in source control.

Im not aware of any bug of that kind in 3.0 and most likely your problem are the units. That said Farseer 3.2 should work just fine with XNA 3.1 ...only the samples won't compile, mainly because of the changed content project structure. But even the samples can be quickly adapted to 3.1.

Jan 18, 2011 at 10:12 PM

Again thx. :)

Units: 5.0f radius, 0.3 density.

I got the impulse working now, my update was this:

float timeStep = (float)gameTime.ElapsedGameTime.TotalMilliseconds);

I copied the timeStep from the testbed:

float timeStep = Math.Min((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f, (1f / 30f));

The impulse is working fine now, but the circle accelerates very slow by the gravity. The world is created like this:

world = new World(new Vector2(0.0f, -9.81f));

What parameter makes it fall faster? It doesn't seem to be the mass or density. :)

Jan 18, 2011 at 11:28 PM

Ok your units were fine then, Step() just expects seconds instead of milliseconds so you were advancing the simulation by several thousand seconds per step ;)

Your gravity, density and object size values are good. Density is used to calculate the mass of an object. Like in the real world all objects receive the same amount of acceleration by gravity which is mass independent (aside vom friction and air drag). So changing the mass has no (and shouldn't have any) effect. Drag can be influenced by playing with the linear damping paramter,  but you probably have not touched that yet. At first just simply try to increase the gravity. I think we use (0f, -20f) in the samples. Farseer does not necessarily produce the best results with "real world" values and getting the physics to feel right requires playing around with the different settings a bit most of the time.

Jan 18, 2011 at 11:45 PM

Yeah, that makes perfect sense and works as expected. :)

Gravity acceleration now looks fine, but there still is a velocity-limit? Would make sense with air drag, but for testing, I set the LinearDamping to 0.00001f, but it doesn't fall faster. :)

Jan 18, 2011 at 11:57 PM

All objects are limited by Settings.MaxTranslation. You can increase that value, but if you set it too high things might become instable and start tunneling through each other and stuff. If you need very fast moving objects also have look at body.IsBullet. That enables CCD (continous collision detection) for fast objects to minimize tunneling errors and achieve more accuracy. Of course that adds quite some computing overhead ;)

You shouldn't run into problems like that with a gravity around 20f though. At least I never had to touch Settings.MaxTranslation even if things were moving a bit faster, so your "problem" may be something else entirely :/

Jan 19, 2011 at 12:06 AM

It's indeed Settings.MaxTranslation, I set it to 4.0f and bullets fall like plumb now. :) Thanks a lot for the support!