0

I my game on android I would like to let my player collide with an invinsible object. This collision should be detected, but it shouldnt actually stop the player. He should just be able to "go through". I'm sure this is possilbe in libgdx but i cant get it to work. I used the tutorial here

I just want to use the trigger. Setting the Flags with btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE does work, which means that my Character goes through, but I dont know where this is saved. So where can I find the Event which has this information, does anyone know?

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
member2
  • 155
  • 2
  • 16
  • So your question is how to implement a ContactListener? Have a look at this tutorial: https://xoppa.github.io/blog/using-the-libgdx-3d-physics-bullet-wrapper-part1/, make sure to read it entirely. – Xoppa Nov 30 '16 at 20:59

1 Answers1

0

I my game on android I would like to let my player collide with an invinsible >object. This collision should be detected, but it shouldnt actually stop the >player.

What you need is a custom ContactListener paired with a Box2D sensor body that it can detect. Your player would also be a Box2D body. Give your two bodies identifier in the form of UserData (e.g. a simple string). You can then check for these UserDatas inside your ContactListener.

Fixture.setUserData(...)

Your ContactListener would implement the Box2D ContactListener and override its methods:

public class MyContactListener implements ContactListener{
@Override
public void beginContact(Contact contact) {
    Fixture fa = contact.getFixtureA();
    Fixture fb = contact.getFixtureB();
    if(fa == null || fb == null) return;
    // ...
}

@Override
public void endContact(Contact contact) {
    Fixture fa = contact.getFixtureA();
    Fixture fb = contact.getFixtureB();
    if(fa == null || fb == null) return;
    // ...
}

@Override
public void preSolve(Contact contact, Manifold oldManifold) {}
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {}

}

The Box2D body and sensor declarations are left as an exercise for the reader.

A beginner tutorial for Box2D can be found here: http://rotatingcanvas.com/using-box2d-in-libgdx-game-part-i/

mtosch
  • 351
  • 4
  • 18