Almost all games use collision to make areas that players can move through, and areas that they can’t, like walls, trees, enemies, and the ground.
The way collision works in these cases is by looking at where a player is about to move, then checking if they are allowed to move there, and then deciding what should happen if that area is occupied by an object with collision.
In dot big bang, there are three different things that could happen, the Response Type:
- STATIC will stop the player, like a wall.
- DYNAMIC will move the object, like a crate you can slide
- TRIGGER will let the player walk through the object, but send an event in code that we can use to activate other code. You can see this in games when you walk into an area, and it starts a cutscene, for example.
The Collider is the kind of shape being used to check collision. The two types you will use most often are VOXELOBJECT and BOX
- VOXELOBJECT tries to use the exact shape of the voxel object.
- BOX makes a cube around the voxel object that it just fits inside of.
Collision works by checking the coordinates of where a player is going, and comparing them to the coordinates of objects around them.
With a rectangular (or box-shaped, in 3D) object, this can be pretty easy, but we can think about how this would get more complicated with an object with more complex shape:
To cut down on unnecessary calculations, try to use BOX whenever you can, and switch to VOXELOBJECT if that makes the player movement around it look distractingly incorrect.