An intro to physics in Unity
Physics in Unity ensures that game objects correctly manage movement, respond to collisions, are acted on by gravity, and other physics forces. Unity also provides different implementations depending on your project design: 2D, 3D, etc.
Rigidbody Components:
Unity uses Rigidbody components to add physics to GameObjects, which come in the form of Rigidbody (for 3D objects) and Rigidbody2D (for 2D objects, obviously).
These components contain variables for defining the object’s mass, linear drag, angular drag, whether it should be affected by gravity, collision detection, and forced movement constraints.
Colliders:
Colliders are the other main aspect of Unity physics. Colliders are also components that can be applied to GameObjects, and can come in many different types for different situations.
Colliders, as the name suggests, manage how objects collide with each other. Like Rigidbody components, there are often a 3D and 2D variant of each collider, with some exceptions.
Collider components are simpler than Rigidbody ones, as they simply define the size, shape, collision type (trigger or not), and optional physics material.
By adding 2 colliders of the same game type (3D/2D) to 2 different GameObjects in a scene, they will collide when they come into contact with each other.
- Collide collision is when objects cannot overlap each other, as their edges hit each other.
- Trigger collision is when objects can overlap each other, and is usually used to trigger events when objects make contact.
I will cover how to code for the Collide and Trigger collision types in a later story.
Physics Settings:
The project global physics settings can be viewed and changed by going to “Edit/Project Settings” then either “Physics” or “Physics 2D”.
Using the Project Settings/Physics or Physics 2D menus, you can change how physics is applied globally to your whole project. Gravity strength, bounciness, cloth and simulation settings, and layer collisions can be modified, among more advanced settings.