Collision in dot big bang can get quite complex but there is no reason to be afraid of it and understanding what’s going on is important for making games. This article should remove some of the mystery without getting overly technical.
|Note: Currently components aren’t shown in the editor. This functionality will be enabled shortly but until then you’re getting a sneak peek.|
In the most basic sense the Collision system in dot big bang is what allows the player to run around, jump on and bump into everything in a game. Different entities are set up with different collision properties and that defines how they will act. For example an entity that represents a piece of terrain should probably let the player collide with the voxels it is made from, so you can walk into caves and run across its surface. Whereas an entity representing water should probably let the player pass straight through.
This is setup using the Collision component. Entities without a Collision component will not take part in any collision. Here is the current view of what properties are on the Collision component:
The Collision component defines many different properties, but for now we’ll take a look at a few of them to understand the main options available.
The Response Type property of the component controls how the Entity will react when a collision occurs. There are three options:
Static means this Entity will not move when collided with. That means if a Static Entity is moving and it overlaps another Static Entity they will remain overlapped. But a Dynamic Entity will be pushed out of a Static one. Most scenery in your game that doesn’t move around should be marked Static.
Dynamic means this Entity can be moved by the collision system to prevent it overlapping other entities. Most things you have moving around in a game want to be Dynamic.
Trigger means this Entity will not move if collided with and Dynamic entities will not be moved out of collision. This is useful for making trigger volumes, invisible areas that the game uses to detect when other Entities enter or leave it. A trigger might spring a trap or cause a door to open or close dramatically behind you.
Perhaps the most important is the Collider property of the component. This defines several different shapes that the collision can take. These shapes are generally separate to the shape of any of the Voxel Object or Skeletal Object components that are on the Entity. Although we offer some help in making the collision shape fit those components.
The shapes available are:
Voxel is the actual voxels that make up the first Voxel Object on the Entity are used as the collision shape. If the voxels are too dense (there are too many in a small space) the collision system will default to using a box the same size as the Voxel Object. If you notice this behavior making the Entity bigger by scaling it up will turn on full voxel collision. This is done because colliding with many tiny voxels is very expensive to calculate. In fact voxel collision is the most expensive kind we have currently so if you can use one of the other shapes instead we’d highly recommend it.
Sphere shapes are positioned by an offset from the Entity position with a set radius. They are extremely cheap and are a good choice for a lot of ‘trigger’ effects like pickups and for Entities that are more naturally sphere shaped like balls.
Box shapes are positioned by an offset from the Entity position and you can define how large it is in each dimension. They are rotated to match the Entity rotation. As well as being great for crates they can be very useful for defining trigger volumes or making large flat surfaces.
Capsule shapes are positioned by an offset from the Entity position and defined by a radius and length of the Capsule. They are also rotated to match the Entity rotation. These are usually perfect for player and NPC collision as the shape is a good match for characters and the rounded bottom helps moving over uneven ground.
Lozenge shapes are positioned by an offset from the Entity position and defined by a width, length and a radius. They are like a Capsule that also has width. These aren’t commonly used but can be useful for entities that fit their shape well.
Entities can have multiple Collision components on them to do different things. For example the ship in Straits of Danger is set up to allow players to collide with the ship's voxels but the ship itself uses a Lozenge to collide with the larger level pieces. If we only had one or the other the ship wouldn’t work properly!
The Collision system in dot big bang also does a bunch of other things. It lets you know when two entities are touching or overlapping with one another. It passes this information to scripts when it occurs or when a test is made from script. It will move overlapping entities so they are right next to each other. If you’re interested in learning more about the advanced details of our Collision system you can read the Advanced Collision Guide (coming soon!).