Detect if stopped moving

Topics: User Forum
Sep 1, 2011 at 12:50 PM


I am new to Farseer Physics and XNA, so please bear with me.

I have a turn based Snooker type game, where the players take it in turns to hit the balls.

However, I would like the game to wait until all the balls have stopped moving until the next player take his turn.

I can’t seem to figure out a way to do this, any help would be much appreciated.


Sep 1, 2011 at 4:39 PM

in your game logic loop, call this function:

public bool BallsMoving()
    foreach(Body b in billiardBalls)
            return true;
    return false;

Sep 2, 2011 at 3:12 PM

Thank you so much

Sep 2, 2011 at 3:22 PM

No problem.  To elaborate a bit more, Farseer tries to be as efficient as possible.  To that end, it doesn't make sense to simulate *every* object, *all* the time, most especially if that object hasn't moved for a long time (relatively, anyway).  Newton's first law in action: An object in motion will stay in motion and an object at rest will stay at rest unless an outside force acts upon it.  Once an object has stopped moving, unless something around it changes, we can stop updating it.  So, after a certain threshold of inactivity, Farseer marks the body as "Asleep", and doesn't worry about it unless certain conditions are met (another object colliding with it, etc.).  So, you can take advantage of this, and use it to find out when all of your balls have stopped moving.