Search code examples
libgdxcollision

Collision detection in libGDX,rectangle overlap and AABB


I made a 2D game for a project using libgdx and my collision detection techique is based on the .overlaps method in the Rectangle and it works fine. I want to understand the implementation behind ,if i was to parallelise it with intersects method i know how it works. But is that only? i'm reading that in discrete collision detection methods not only is needed to calculate if the entities collide but "how much" (the depth of collision) they have collided and the Axis Aligned Bounding Box algorithm is used in order to push the entities back. First of all i'm confused if the rectangle overlap tecnhique is the same as the AAAB in libgdx and secondly the implementation details the overlaps method in the Rectangle class in libgdx encapsulates are the same as the intersects method in the Rectangle class in java or has to do with the AAAB algorithm as well? Thanks and i hope you can clarify that for me.


Solution

  • I will keep it short since you can check the source code for all libGDX's collision implementations. So, no matter what you use from libGDX won't work perfectly if your objects are moving too fast to register a callback. For collision, use box2d.

    If you don't want to use box2d, another approach could be implement something like this.

    Update: This explains pretty good.