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

Difficulty from Farseer 2.1.x to 3.0

Topics: Developer Forum, User Forum
Feb 25, 2011 at 6:53 AM

I'm well aware that converting to Farseer 3.0 mid project was discouraged, but I thought I'd give it a try, and I ran into a few areas where I couldn't find an analogous solution in Farsser 3.0. I took guesses at possible solutions, but I'd appreciate some help:

  • PhysicsSimulator::GeomList - I used this to check if there was any non-static object in the path of where I was going to move an object to. I was just updating the position of this (static) object frame by frame rather than applying a force or velocity to it. I'm guessing I would want to create a sensor fixture and test against that?
  • Geom::GetNearestDistance - I used this as part of the above issue. I'd compare the nearest distance to a threshold, so I guess I want to create a sensor fixture that is a circle of the threshold radius?
  • PhysicsSimulator::ProcessAddedAndRemoved - Is this done automatically by World when you create a Body/Fixture?
  • Contact::Separation - I was checking the separation between two colliding objects (in OnCollision) to see if the impact was "hard enough" to warrant playing a sound effect. Is there a way to determine this using the physics engine, such as getting the force of the collision?
  • PhysicsSimulator::Enabled - I think I originally used this because I didn't want to update the simulation but wanted to process added and removed....or something. Its purpose for my game somewhat snowballed out of control after that. Is calling World::Step with a dt of 0 acceptable to emulate that the simulation isn't running? Can I just not call World::Step and rely on the World to keep Body/Fixture info up to date as I add them into the simulation?

Any help would be greatly appreciated.




Feb 25, 2011 at 11:45 AM

Point 1 and 2: Not 100% sure what your problem is. If you want to move around bodies manually have a look at kinematic bodies. Should not moving to where other objects are happen automatically as part of the collision detection? Anyway if you want to test against some kind of "invisible" object or trigger, you should use sensors exactly the way you described it.

Point 3: Yes this is done automatically upon the next timestep.

Point 4: There should already be some discussions here how you can get the impulse. Here is an excerpt from the box2d manual on how to determine the approach velocity in the PreSolve event (in C++):


void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
  b2WorldManifold worldManifold;
  b2PointState state1[2], state2[2];
  b2GetPointStates(state1, state2, oldManifold, contact->GetManifold());
  if (state2[0] == b2_addState)
    const b2Body* bodyA = contact->GetFixtureA()->GetBody();
    const b2Body* bodyB = contact->GetFixtureB()->GetBody();
    b2Vec2 point = worldManifold.points[0];
    b2Vec2 vA = bodyA->GetLinearVelocityFromWorldPoint(point);
    b2Vec2 vB = bodyB->GetLinearVelocityFromWorldPoint(point);
    float32 approachVelocity = b2Dot(vB � vA, worldManifold.normal);
    if (approachVelocity > 1.0f)

Point 5: Running World::Step with a dt of 0 is perfectly fine. We use it in the testbed and the samples framework to pause the simulation. Adding and removing Bodies should not interfere with it and work like with any other timestep too.