Stopping Physics Behaviors

Sep 8, 2009 at 4:05 PM

Another question - is it possible to stop applied physics behaviors after some time?
For example, If I add a Torque or Force behavior to an element, can I stop that movement somehow after a few seconds or even let it fall of gradually to zero?

For now, the element just continues to spin or move ...

Thanks
Koestie 

Coordinator
Sep 8, 2009 at 4:12 PM

There is no Behavior for this, but you could do it by directly accessing the underlying Farseer physics objects. There is some info on the "Home" wiki page about this under Coding Techniques but it would basically go like this:

First get a reference to the main PhysicsController -

PhysicsControllerMain _physicsController = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain;

You can then get at the GeometryObject and BodyObject for each of your objects (if you're unsure of the name of the objects, just place a watch on the PhysicsObjects dictionary and see what you have in there).

The code below is just a guess, I might be wrong on the method names but I think you would want to do ClearTorque and ClearForce...

_physicsController.PhysicsObjects["ball"].BodyObject.ClearTorque();

The Farseer Engine has lots of properties that are not exposed in the Behaviors or Physics Helper controls. You can learn more about them at http://farseerphysics.codeplex.com.