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 ...

Get Building a 3D Game with LibGDX now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.