I’m developing a plane fighter game and I’m having some problems when calculating the flight path…
When the plane sensor collides with some object in his radar, he is supposed to turn to some direction to avoid it, but I’m unable to do it because I can’t find exactly where was the collision.
I’m using this(only relevant part):
public void beginContact(Contact contact)
{
Fixture f1 = contact.getFixtureA();
Fixture f2 = contact.getFixtureB();
int numpoints = contact.getWorldManifold().getNumberOfContactPoints();
WorldManifold wm = contact.getWorldManifold();
Vector2 point0 = new Vector2(wm.getPoints()[0].x, wm.getPoints()[0].y);
// ...
}
The var point0 always have values (0,0) and worldManifold.numContactPoints always = 0. Why?
It’s colliding a sensor and a static body.
The only difference from this tut ( http://www.iforce2d.net/b2dtut/collision-anatomy ) is that I’m using libgdx, tileAtlas, and tileMapRenderer to build the world so all static fixtures are attached to the same body.
Sorry if this is a noob question, I couldn’t find a solution in a few days.
Also posted here: http://badlogicgames.com/forum/viewtopic.php?f=11&t=5417#p25961
Thanks
Collisions with sensor fixtures do not cause any collision response, so there are no points in the manifold, because the engine does not need to calculate them.
If you need collision points without having any collision response, you can change the sensor status so that both fixtures are not sensors, then in the BeginContact and PreSolve functions of your contact listener you can do contact->SetEnabled(false) so that no collision response occurs.