Introduction to Physics in Unity
A collision occurs when two gameObjects touch. Each object has a Collider property. In the shooter game project, the Inspector lists a shelf item of Collider that keeps track of the shape of the object.
The object’s shape provides coordinates in the game space to use to identify when a collision occurs. Starting out collisions have no effect on objects as they drift or run through each other without incident until Unity physics is linked as a component to create rigid bodies from the coordinates of the gameObjects.
Physics is enabled to an object in order that collisions between object can be detected. Then game logic can be added to deal with the collisions.
The rigid body is the way to add Physics to a gameObject.
There are two types of collisions when objects’ meet:
- Hard surface collisions for two objects bump, bounce, crash, and hit, resulting in a destruction, change of direction, or a clumping or a damage — a physical event.
- Trigger collisions for two objects collect, infect, inventory or initiate a message. A notification is created, but no physics involved.
As a games’ progress is visually represented in different ways, consider how the use of the two types of collisions can be put to use.
Consider:
- An player object crosses a finish line. There are no changes to the player, the finish line, but a timing clock stops and the spectators go wild
- two objects touch and their directions change, one disappears.
- An object increases speed and changes color, or runs out of fuel and it’s speed slows into a glide.
- one object eats another object and changes appearance or grows in size.