Hands-On Game Development with WebAssembly
上QQ阅读APP看书,第一时间看更新

Compound colliders

A compound collider is when a game object uses multiple colliders to determine whether there was a collision. We are going to use compound circle colliders on our ship to improve the accuracy of our ship collision detection while still providing the increased speed of using circle colliders. We will cover our player's ship and our enemy ship with three circles. Our projectiles are a circle shape, so using a circle for those is entirely natural. There is no reason you need to limit compound colliders to using only one shape of collider. Internally, a compound collider could mix circle colliders with rectangle colliders or any other type you like.

The following diagram shows a hypothetical compound collider made up of a circle and two rectangle colliders:

A compound collider composed of three basic colliders

In the next section, we will learn how to implement a basic circle collision detection algorithm.