Colliders

Collider components define the shape of an object for the purpose of physical collisions. You can think of this as an invisible box that is an object that permits it from passing through it but without coming into contact. They don't have to be the same shape as the visual representation (Mesh, Sprite) of the object; in some cases they can be a simple primitive type (for example, Box Collider, Sphere Collider (only in 3D), and Capsule Collider), but the closer to the actual shape, the better. If you're using many different primitive types of colliders within Unity, you can combine them to create what is called a Compound Collider.
In 2D, you can also use what is called a Polygon Collider 2D or Edge Collider 2D. A Polygon Collider 2D is a collider that is shaped by freeform edges that you can adjust so that it better suits your Sprite. It must also enclose the edges of the area that it is trying to provide a collider around. An Edge Collider 2D is defined by a freeform edge made of line segments, so you can adjust it to fit the shape of a Sprite with great precision. In general, Edge colliders are best for surfaces (for example, game platforms) because you are only generating geometry where you need it.

Another important thing to consider when using colliders is the type of Material that they are made of. For example, a player jumping on a springboard is going to result in a very different behavior than landing on spikes. Applying Physics Materials to objects can be done to 2D objects by using Physics Material 2D. It is important not to forget the "s" as Physic Material (without the "s" in Physics) is reserved for 3D Physics Materials. Lastly, Physics Materials in Unity 2D have two properties: Friction and Bounciness, as in the following image. We will touch on these later for Project 3 - RETROformer:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset