Table of Contents

CollisionGroups allow users to categorize colliders into different groups. CollisionTables define the relationships between those groups and the behavior of those colliders when they collide with one another.

Learning Objectives

  • CollisionGroups
  • CollisionTables
  • CollisionGroup relationships

Level Setup

Before jumping into how CollisionGroups are used, we need to set up a simulation to use them in.

Collision Groups

A CollisionGroup is a resource assigned to one or more colliders, usually before the game is run.

image

CollisionGroup enum property on the SphereCollider component

  • Command : Add Resource
  • Create a CollisionGroup resource using the Default template template and name it SkipResolution
  • Command : Add Resource
  • Create a CollisionGroup resource using the Default template template and name it SkipDetection
  • Select : SkipResolutionSphere object
  • In the Properties Window
  • Under SphereCollider
  • Set CollisionGroup enum to SkipResolution
  • Select : SkipDetectionSphere object
  • In the Properties Window
  • Under SphereCollider
  • Set CollisionGroup enum to SkipDetection
  • Command : PlayGame

notable

You will notice that the behavior of the balls has not changed as of yet. This is because in order for CollisionGroups to be used, they must be included in the space's CollisionTable.

CollisionTables

A CollisionTable defines the relationship between CollisionGroup pairs.

  • Command : Add Resource
    • Create a CollisionTable resource using the Default template template and name it GameTable

When a CollisionTable is created, the CollisionTableEditor Window opens.

image

The CollisionTableEditor Window

This is the default configuration for a CollisionTable. It takes all the existing CollisionGroups and generates a permutation table of all the pairs.

  • In the CollisionTableEditor Window
  • Set DefaultGroup / SkipResolution to SkipResolution
  • Set DefaultGroup / SkipDetection to SkipDetection

setting_Tables

notable

You are probably wondering why the groups still aren't working. There is still one more step to perform for the groups to take effect: we have to tell the Space to use the CollisionTable we have created instead of the default CollisionTable.

image

Setting the CollisionTable enum property for the Space

noprint

Now we can see the two spheres, which are set up to skip resolution and detection respectively, fall through the platform as expected. We still need to prove to ourselves, however, that the SkipResolutionSphere object is still at least detecting the collision.

  • Command : Add Resource
  • Create a NadaScript resource using the Component template template and name it PrintCollision
  • Update the PrintCollision script to the following:
class PrintCollision : NadaComponent
{
  function Initialize(init : CogInitializer)
  {
    Zilch.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
  }

  function OnCollisionStarted(event : CollisionEvent)
  {
    Console.WriteLine("CollisionStarted: `this.Owner`, Other: `event.OtherObject`");
  }
}

printcollision

CollisionGroups properly configured, and printing collision detection

As can be seen by the printed message in the above image, the SkipResolutionSphere object is indeed detecting collision, whereas the SkipDetectionSphere object is not.

Collision groups and tables allow for a lot of flexibility in the usage of collision for game logic. They can also allow for significant performance improvement in games that heavily use physics.

Related Materials

Manual

Reference

Commands

Classes

Events

Enums

Development Task

  • {T1176}