Building Worlds in dot big bang

0 of 6 lessons complete (0%)

Collision

You don’t have access to this lesson
Please register or sign in to access the course content.

Overview

Collision makes a level feel real by deciding what objects a player can move through, but can also be used to script behavior based on where different objects are, and customized to make different objects behave differently when collided with. You can customize the shape that collision takes (the collider), what should happen when something else with collision touches it (the response type), and even use separate objects to create a custom collision shape.

Adding and Removing Collision

With an entity selected, you can change its collision through the Entity Props panel. Collision will be the third section in the left side toolbar, after Entity and Transform, symbolized by the purple Collision icon. Hover you mouse over this icon and click the Add Item icon to add collision to the entity. When you make an entity by dragging a voxel object it will have collision by default.

Not every entity needs collision! You can delete that collision by mousing over the Collision Volume section of the menu, and then clicking the Remove Item icon.

Colliders

Colliders are how we define a 3D area in space that will detect if something is inside its boundaries. There are several different options for the shape of these colliders: see the full list here. In this lesson, we will focus on BOX and VOXELOBJECT collider types.

By default, entities will have the VOXELOBJECT collider type, which matches the exact shape of the object. This creates the most realistic collision experience.

The BOX collider type is the simplest collision, as it creates a box that goes around the longest dimension of the voxel object by default. It can be the clearest to work with when you are scripting a reaction to the collision and need to detect when a player enters an area or is touching the edge of an object. The SPHERE, CAPSULE, and LOZENGE collider types work the same way, just fitting a different shape around the dimensions of the voxel object.

Collision Response Types

The Response Type property on a collision volume determines what should happen when something collides with the entity.

By default, entities have a STATIC response type. If a player tries to walk through an entity with static collision, they will simply not be able to go any further once they touch the edge. You can see this collision on the Ground entity that is part of default games, and might use it for walls or heavy, immovable objects.

With the DYNAMIC response type, when a player walks into the object, it will get pushed in the direction the player is moving. Dynamic responses allow you to define how many entities interact when colliding with each other. Use the Layers property to define which things collide with each other — entities need to have the same layer to collide — and the Priority property to define which one will move.

The TRIGGER response type won’t prevent you are or another entity from passing through the collider, but will create scripting events — one for when the collision first starts, one that repeats as long as something is inside the collider, and one for when an entity stops colliding — that you can use to define what should happen when something enters or leaves an area.

Custom Collision

If changing the collider and collision response isn’t enough to create the experience you want in game, there are several ways you can continue to customize your collision.

For the BOX, SPHERE, CAPSULE, and LOZENGE colliders, you can change their size and position in the entity. The Offset property changes where the center of the volume is relative to the center of the entity. Depending on the collider type, you can customize the size by changing a combination of Width, Height, Depth, and Radius values.

You can also add more than one collision volume to an entity. If you want an entity to keep voxel collision, but would also like to have a larger trigger collision in a box shape around it, you add another collision volume and give it those properties.

Finally, you can also create an entirely new entity to represent the collision. This could be useful if you only want some of the voxels to have collision, or if you are having a hard time getting the player into or through an entity. First, remove the collision volume from your entity. Then, create and add a new entity that will represent the collision. Turn the Visibility property off to make keep the voxel object collision without showing the voxel object.

You can even make your second collision entity a child of the main entity by changing its Parent property in the Entity section, so that when you move the main entity the collision entity moves with it.