Collision
Now we will implement collision, and by collision we actually mean collision detection. We will detect whether two objects are currently colliding with each other. We can then create appropriate actions. Not that we will not actually implement the physical collision (for instance a car hitting the wall). If we want to do this, we should use a physics engine.
We will make a difference between 2D collision and 3D collision. When testing for collision of two 2D game objects, we use rectangles. This rectangle surrounds the object, and we can then check whether these rectangles intersect with each other. Note that if you have a cross for instance, the bounding rectangle will be too big for the object, but for our intended purposes, a rectangle will do just fine.
3D collision is very similar to 2D collision; the only difference is that we will use the BoundingBox
class instead of the Rectangle
class. All the steps are the same as with 2D collision, but we make use of 3D coordinates. This...