Unity Physics
Objective: Introduce Unity’s built in physics
Unity’s physics engine is accessed utilizing Rigidbodies, Colliders, Joints, Articulated Bodies and Character Controllers.
Rigidbody: A game object must have a rigidbody to use the physics engine in Unity to assign the mass, drag and angular drag. The object can now be effected by gravity, if checked, and collisions. In the image above, the pink sphere has a rigidbody component and a script attached that allows the input of force to the _rigidbody component using the vertical and horizontal axis. The pink ball initially falls due to gravity. On force input to the rigidbody using, _rigidbody.AddForce(new Vector3(horizontalInput, 0, verticalInput) * _thrust), the pink sphere accelerates until a collision. If Is Kinematic is checked the object is isolated from Unity physics.
Box Collider: These are meshes, or surfaces, that trigger collisions and can be used to interact with other game objects via scripts or the physics engine. The light blue floor and tan walls have colliders, but no rigidbody. The floors and walls can stop an object with a rigidbody, like the pink sphere, but are not impacted by physics. If the IsTrigger is checked the collider does not impact physics but is used for event detection.
Spring Joint: You may have noticed the orange ball following the pink ball. The pink sphere has a joint, specifically a spring joint, that connects it to sphere(1). Within the Spring joint the springs properties can be defined. This is one example of a joint. A joint does not require a parent child relationship. Joints allow the physical connection between objects.
Articulation Body: Is used to simulate joints but requires a parent child hierarchy. The three green cylinders are in a parent child relationship shown below and are each connected by spherical joints, as might be found an arm.
The anchor position and rotation of the joint to the parent can be adjusted in the inspector. The properties of the joint can also be adjusted. As the spheres collide with the green cylinders, they remain connected via the joints.
Character controller: A character controller allows the game object to interact with static colliders, such as walls and floors. The character controller can push other rigidbody objects aside, but is unimpacted by momentum from other rigidbody objects. See how the yellow player capsule remains upright and does not topple over. It also does not move on impact by the spheres or cylinders. The height and radius of the capsule collider can be adjusted in the inspector to fit the model. This allows a Unity developer to script the behavior for the player using altered momentum restrictions.