Colliders - SkaterXLModding/skater-xl-mapping-wiki GitHub Wiki

Header

Table of Contents

Welcome

This wiki page will cover collider types, when to use what, and the concept of generating colliders in different applications. While this guide will attempt to document as much information as possible related to this topic, it is important to remember that the world of game development can be very open ended, and there are always multiple ways to accomplish the same task. As always, be sure to check the external information sources to find more documentation on the topic.

Introduction

Before diving headlong into covering the details of colliders, it is first important to understand what is a collider. The collider component of a Unity game object is used to define the physical shape of a mesh for the purposes of physical collisions. The collider of a mesh does not to be an exact copy of the Mesh Renderer component, and a general approximation of the mesh shape will generally function just fine, and often better than a true 1:1 of the mesh. In comparison, a Mesh Renderer component is used to define the visual shape of a mesh, or what the player sees. To help visualize this, take a look at the example images below.

Here we can see the mesh renderers of various shapes, this is what the player would see in game. With no colliders applied, these would essentially be ghost objects. Visible, but the player would not be able to physically interact with them.

image

This example on the other hand, is a visual of the corresponding collider types to the shapes shown above. These game objects have the Mesh Renderer component disabled. The green outlines are only visible in the editor to visualize colliders during the creation process. If we were to leave these as they are and load into the game, we would see nothing, but still be able to bump into the physical objects.

image

Here we can see the Mesh Renderers overlapped with the their colliders. Again, the green outlines are editor only, and not visible in game. These objects would be both visible, and interactable in game.

image

Collider Types

Colliders come in a variety of shapes and types, and they function in various ways. All colliders of any kind fit into one of two categories: primitive and nonprimitive. Primitive colliders, or basic colliders, are simple colliders that are the least processor intensive. Nonprimitive colliders are more complex shapes, and are far more processor intensive. As such, we as environment designers do our best to use primitive colliders whenever possible, to save on performance. Although the impact of using mostly nonprimitive colliders is negligible in small environments, it very quickly compounds on larger projects, and will eventually lead to serious loss of performance.

Primitive Colliders

Primitive colliders in Unity 3D come in 3 forms: Box, Capsule, and Sphere. You can see the left 3 shapes in the above example images for visual examples of each of the primitive collider types.


  • Box

Box colliders are a simple rectangular prism. This shape can be adjusted along the 3 axes using the adjustment handles.

image

In the inspector we see only a few variables to control with this collider type. The Edit Collider toggle button allows us to enable and disable the 3D viewport handles on the collider, which is how we can easily adjust the shape in 3D space. Is Trigger is a function of coding, allowing the user to make the Box Collider component operate as a space that when entered by another 3D shape, will trigger a script. We rarely use this in SXL map creation, although one way it could be utilized is by using multiple Volumes in a scene. For more information on the topic refer to the wiki page on Post Processing. The Material input allows us to add a Physic Material that can be used to adjust the bounciness and friction values of the object. The Center values allow for moving the origin point of the collider around without moving the game object itself. Similar to the Center, the Size values allow for the adjustment of the size of the collider, without using the handles or scaling the game object.

image


  • Sphere

Sphere colliders are exactly as they sound, a sphere. This collider can be scaled, but not distorted.

image

The inspector for the Sphere is similar to the box. The primary difference being rather than Size we have radius, this one value drives the size of the sphere.

image


  • Capsule

Capsule colliders function as a cylinder with round caps.

The inspector panel for Capsule colliders is quite similar to Sphere and Box with a few slight differences. Much like Sphere, there is a Radius value. This adjusts the width of the collider along its circular axis. The Height value is how we adjust the size along its height axis. The Direction dropdown is what drives the orientation of the capsule's height axis.

image

Nonprimitive Colliders

Nonprimitive colliders in Unity 3D are: Wheel, Terrain, and Mesh. As environment designers, we commonly use Mesh and sometimes also Terrain colliders. We will not discuss Wheel colliders in this guide at all, but feel free to read up on them here. To see a visual example of a Mesh collider refer to the skater model in the above example images.


  • Mesh

Mesh colliders are the primary form of collision we as SXL mappers use in the Nonprimitive collider category.

image

In the Mesh Collider component inspector we can see a variety of options and variables. Convex is an option that can be enabled to remove gaps and concave shapes from the collider mesh. This can be useful at times, and is primarily used because normally two Mesh colliders can not collide with one another, so convex is used on one to allow them to interact. We can also use the Convex option to slightly simplify a mesh collider at times. This can help with clipping issues, by making the mesh more "solid", as well as slightly improve performance. Below is a visual of our mesh collider example set to Convex

image

Convex colliders tend to be lower tri-count, which can improve reliability and performance

Much like our other collider types, this can be set to Is Trigger, but only so long as it is also set to Convex. We are going to not cover Cooking Options in this guide, as it is not particularly relevant to SXL mapping, if you'd like to learn more on the topic take a look at this unity manual. The Material input in this case is just like the other collider types, allowing for a Physic Material to be used. Finally, the Mesh input, is where we can select what 3D mesh to be used to generate the collider. When adding a Mesh Collider component to a game object, it will attempt to use the Mesh Renderer reference mesh as the collider mesh by default.

image


  • Terrain

A Terrain collider is automatically generated when creating a Terrain game object. It is an optimized type of Mesh collider intended for use on Unity Terrain objects only. If you'd like to learn more about using terrain, check the manual.

image

Optimization

Multiple Primitives

A core concept as a mapper is to optimize collider usage. Using primitive colliders whenever possible is very important, as it can greatly improve performance on larger projects with a high collider count. It is a very valid technique to use multiple primitive colliders, in stead of using one mesh collider. This is a very useful technique in a lot of cases. For instance buildings, cars, and props that don't necessarily need the collider to be a 100% accurate representation. Such cases can use a collider approximation rather than a truly accurate collider. The example below is a visual example of this concept. If we wanted the skater model that we use as a reference to be an object with collision, it is very easy to approximate the mesh for collision purposes. On the left is the model with a mesh collider applied. The model itself has roughly 1.7k triangles, each one of these adds to computational time for the end user of the game environment. On the right; however, we have approximated the mesh with 2 capsule colliders. At the scale of the skater model, and for the purposes of simply being something the skater can bump into in game, these simple capsules will essentially give the player the exact same result and feel as the mesh collider. However we are saving substantially on performance, as we are not using 1.7k tri's worth of mesh collider processing power.

image

Grinds

Another key time to use Primitive colliders as much as possible is when creating grinds. Beyond just the performance increases this can have, it will also produce more reliable grinding surface. Rails for instance, can have clipping issues with mesh colliders, where the board pushes through the rail when popping out. Using a capsule collider, or multiple, in stead will result in a far more stable surface with much less clipping. Even with capsule colliders, it is still recommended to keep a capsule thickness of over .03 to prevent clipping issues. Anything thinner may result in unstable grinding conditions.

Related Wiki Pages

External Information Sources

Unity Manual - Colliders

Back to Top