O'Reilly logo

Building a 3D Game with LibGDX by Elmar van Rijnswou, Andreas Krühlmann, Sebastián Di Giuseppe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding physics and collisions

So, now we have the ability to create entities. However, these entities will have to interact once they collide. For example, when an enemy hits the player, damage should be done. Or when the player hits the floor, it should not fall through.

Essentially, this can be done the same way as it is done with 2D, except for the fact that one more axis requires to be checked. First we will look at simple collision methods, where we will encapsulate the object to be checked in the smallest rectangle possible.

One way to do it is where two rectangles are checked for collision. The condition for the collision would be when all the axes of one rectangle are contained in the other rectangle. However, this adds a lot of performance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required