2

Using the physics helper library.

I'm trying to figure out how I can determine whether a physics object is at rest. Does anyone know how to do this or have any ideas of what I could do?

An example scenario is a bouncy ball that can be picked up and thrown around. I tried creating a timer that times each individual bounce from a collision event with the floor and determines if the object is at rest based off of that but this does not work for if the user slides the ball to the left and right.

Any suggestions?

Tom
  • 1,187
  • 2
  • 12
  • 21
  • Doesn't Farseer have some built-in mechanism for detecting if an object is at rest so it can be put to sleep? – Andrew Russell Jul 24 '11 at 17:41
  • I was looking for a state of some kind but I can't find one. With the physics helper each object acts like a farseer BodyObject and it really just allows you to get the position of the object as well as apply force, impulse ect. – Tom Jul 24 '11 at 17:52

3 Answers3

2

If you have runtime access to the underlying Farseer Body, then you also should have access to the property LinearVelocity, which you can check for 0 magnitude.

DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
1

This is pretty basic stuff. Your physics object should be an instance of some kind of class which contains information on the object's position, velocity, etc etc. At any given time, you should be able to check the speed of the object, and obviously if its speed == 0, it is at rest.

Jon Martin
  • 3,252
  • 5
  • 29
  • 45
  • There is no speed property when working with physics object using the physics helper. – Tom Jul 24 '11 at 17:15
  • That's pretty dumb. If that's the case, I would create my own physics class. – Jon Martin Jul 24 '11 at 17:16
  • For what I'm doing it was easy to use the physics helper because it uses behaviors. But yea kinda frustrating at times. – Tom Jul 24 '11 at 17:23
  • 1
    Does the class have a momentum property? – CodesInChaos Jul 24 '11 at 17:41
  • It does not. The thing is with the physics helper you can simply create an ellipse in blend and give it physics properties like restitution, mass ect. Then you can manipulate the object as a Farseer BodyObject in the code behind. The body keeps track of world position. It is basically a point is space that is affected by forces such as impulses from collisions and gravity. It doesn't have any states that help me other than position. Might just create my own physics class. – Tom Jul 24 '11 at 17:49
0

So far I've came up with a simple method. Creating two class variables (Vector2 currentPosition, Vector2 previousPosition) and then creating a dispatcher timer that ticks every so often and using the following tick method:

void bounceTimer_Tick(object sender, EventArgs e)
    {
        currentPosition = ball.Position;

            if (currentPosition == previousPosition)
            {
                // Object at rest
            }
            else
            {
               // Object moving
            }
        }

        previousPosition = currentPosition;
    }

There are some issues with it though for example if it captures the balls position in the air coming up and then back down at the same position (very unlikely) and at a very high frequency in ticking it can sometimes capture the same position unexpectedly, at a slow frequency of ticking it takes time to determine if the object is at rest, anyone else have a better method?

Tom
  • 1,187
  • 2
  • 12
  • 21