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

How To Find: A Body at Rest

Topics: Developer Forum
Aug 25, 2012 at 8:39 AM

Imagine thus:

Character has a box, character throws a box, box hits the ground, slides, and when it is done. It POPs.


Interesting! No?!!?


Anyway, how can I detect when the body is at rest? To activate the POP.

I am trying onCollision, then scanning variables, however, onCollision dosen't happen often enough to detect when its LinearMovement is done. (furthermore, I scan to see if the collision is with the proper surface) Is there something I am missing, an event or variable to wait for?


A little code for giggles:

//I use a class of 
//Box : Body
    this.OnCollision += OnGround;

        private bool OnGround(Fixture fixtureA, Fixture fixtureB, Contact contact)
            bool assign = typeof(Tile).IsAssignableFrom(fixtureB.UserData.GetType());
            if (
		typeof(Tile).IsAssignableFrom(fixtureB.UserData.GetType()) //this works, no issue with it.
		 && LinearVelocity.Length < 5f) //this is a hacky version, which is insufficent, but good enough to test with before refining

                return false;
                return true;


Thanks for any advice/input/alternatives,

Please disregard the code, I only supply it because those ninnys at StackOverflow will have a tiny little stroke if you don't give them something to edit and ask incessant questions about.

Aug 26, 2012 at 1:36 PM

I'm not sure this helps much, but sounds like a box should monitor it's own motion for when it should pop or not. Then you could look at when its average velocity over X frames drops below a small fraction (I think checking for 0 velocity could provide some strange behaviour in rare cases, like a upwards moving box bringing brought down with gravity might hit 0 velocity during the change direction. The box can listen out for a floor collision, if this is a prior stipulation of the pop.

I probably use farseer a little differently to some people. My game objects inherit from the Body, so it's easy to run self checking code once a frame during their own update.

Aug 27, 2012 at 6:40 AM

A agree with your thoughts on checking for 0 velocity, that's why I mixed it with a while in contact with what the heck ever.


my box extends body as well, and doesn't have an update itself. I didn't put updates on my body extended things, trying to keep processing down. Guess I will, Curses!

Aug 28, 2012 at 12:18 AM

Bodies sleep when they are at rest. Bodies have an Awake property that is set to false when the body falls asleep. They are checked against a linear and angular movement tolerance (defined in Settings.cs). They have default values that should be sufficient for most games, so what you can do, is you could check against this property on each update, and if it is false, then you make the pop event happen.