Colliders

A Collider is an invisible shape which is used to understand when two or more components come into contact during a physics simulation. They are a crucial component in any physics simulation, as they allow the simulation to determine how objects should interact when they collide.

When no collider is explicitly added as a child of a Rigid Body, a default collider will be created if there is a Rigid Body Behavior assigned.

Colliders can take on many forms - including simple geometric shapes like spheres and boxes - or more complex shapes defined by a mesh or a convex hull. The sections below go into detail about colliders in Mattercraft.

Adding your own collider type offers several benefits:

  • Transformation of colliders in the editor.
  • Ability to create compound colliders by combining multiple Collider children.
  • Flexibility to assign PhysicsMaterial components to individual colliders for more advanced physical properties.
  • For Mesh Colliders, the ability to source the mesh from any component in the Hierarchy.
  • Options to control whether or not to include all children of a mesh when building the collider.

Adding a Collider

To add a collider, right click on your object in the Hierarchy and add a New → Physics → Collider.

Adding a Collider

Colliders must be direct children of a component with the Rigid Body Behavior for proper functionality.

Colliders come with two (2) main properties:

  • Shape
  • Target Mesh

Colliders are depicted in the viewport by a green bounding box. These are not visible at runtime.

Shape Collider

A Shape Collider uses a simple geometric shape to define a Rigid Body’s collision volume. This is the least costly collider in terms of performance, and thus should be the default used where possible.

Shape Collider: Sphere

You can use multiple shape colliders to enhance your mesh with a reduced impact on performance (compared to the following collider types).

Using multiple Shape Colliders

Mesh Collider

A Mesh Collider uses a mesh to define a Rigid Body’s collision volume. This is the most costly collider in terms of performance, and thus should be considered carefully.

Mesh Collider

You must update the Target Mesh property for the Mesh Collider in order for it to wrap to the desired object.

Convex Hull Collider

A Convex_Hull Collider uses a mesh and minimum geometry to define a Rigid Body’s collision volume.

This is less costly than a Mesh Collider, but more expensive than a Shape Collider, so is good for more complex meshes which may be too costly with the former, but too specifically shaped for the latter.

Convex_Hull Collider

You must update the Target Mesh property for the Convex_Hull Collider in order for it to wrap to the desired object.

Next article: Physics Material

zapcode branded_zapcode i