To find out where the collision occurred, you need to know that sometimes there is not only one collision point, but also many points.

(Image extracted from this manual )
As indicated in this guide,
Box2D has functions for calculating contact points for overlapping shapes. [...] These points [...] group them into a structure of diversity. [...]
Normally, you do not need to directly calculate the contact collectors, however, you will probably use the result obtained in the simulation. [...] If you need this data, it is usually best to use the WorldManifold structure [...].
You can access it in the Contact c class:
public void beginContact(Contact c) { System.out.println("CONTACT"); WorldManifold worldmanifold; worldmanifold = c.getWorldManifold(); for(Vec2 point : worldmanifold.points){ System.out.println("Contact at : [" + point.x + ", " + point.y "]"); } }
It is important . I have never used this library (JBox2D), however I am familiar with it (since libGDX apparently uses a similar one (Box2D)). Also, I don't know if JBox2D is Box2D (C ++) for Java, and if JBox2D and Box2D (libGDX alone) are connected at all. Perhaps some methods may change ( point.x may be point.getX() ).
You can check this site , but this is for C ++ (I use their answer to answer you).
Alex sifuentes
source share