I’m trying to process a collision between a projectile and an enemy. When a projectile hits enemy it have to disappear, but instead a game is crushing in the moment of contact. I don’t know how to fix that
public class CollisionProcessing implements ContactListener {
World world;
public CollisionProcessing(World world) {
super();
this.world = world;
}
@Override
public void beginContact(Contact contact) {}
@Override
public void endContact(Contact contact) {}
@Override
public void preSolve(Contact contact, Manifold manifold) {}
@Override
public void postSolve(Contact contact, ContactImpulse contactImpulse) {
Fixture A = contact.getFixtureA();
Fixture B = contact.getFixtureB();
if (A == null || B == null) return;
if (A.getUserData() == null || B.getUserData() == null) return;
if (A.getUserData().equals(3)) {
System.out.println("Bullet Body collision");
A.getBody().setActive(false);
world.destroyBody(A.getBody());
}
if (B.getUserData().equals(3)) {
System.out.println("Body Bullet collision");
B.getBody().setActive(false); // this
world.destroyBody(B.getBody()); // and this commands cruch game when contact happens
}
}
I have tried world.destroyBody() and body.destroyFicture() but it does not help
New contributor
Happy Trash Bin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.