Unity is a powerful game engine used by a lot of developers to create interactive real time 2D and 3D games. While Unity has a variety of features to facilitate game development, the most important feature is the game physics system which makes the gaming experience more realistic.
There are variety of essential features in the UnityEngine
which helps in managing physics of the GameObjects
.
Some of the most important features are discussed below.
Movement: It allows you to control the movement of your game object. You can move your character forward, backward, up, or down depending on the specified keys in the settings.
Collision: It offers a built-in collision detection feature to record the responses whenever your game object collides with other game objects.
No physics engine dependence: Character Controller does not depend on the physics engine which means that you have greater control over the actions of your game objects. Thus, you can specify how the objects reacts.
CharacterController component: In order to use the Character Controller, you need to add the CharacterController
component to your game object or player.
Rigidbody
physicsProperties: A Rigidbody
is a component in Unity which you can add to your game object. It allows the object to behave according to the laws of physics, such as gravity, velocity, acceleration, force, and torque.
Gravity: The Rigidbody
component has this property set to true. It allows you to specify whether the game object can be affected by gravity.
Is Kinematic: The object cannot be affected by physics if this property is set to true. It is mainly useful for moving platforms.
Collision detection: Rigidbody
along with the Collider components help to trigger events and physical interactions.
Mass, drag, and angular drag: Rigidbody
includes properties for mass,
Collider components: Colliders define the shape of a GameObject
for physical collisions.They specify the space which the game object occupies.
Collision events: Collision events are specified in the C# scripts. You can add the script to GameObjects
which has the collider components.
Rigidbody
and colliders: Collision only happens between the GameObjects
when at least one of them has a Rigidbody
component attached to it.
Colliders are components which define the shape of a GameObject
for physical collisions.
Unity offers different types of colliders each of which are given below.
Sphere Collider: It is a simple collider in the shape of a ball which is suitable for spherical objects.
Box Collider: It is a simple cuboid shape collider which is suitable for objects with box shapes.
Capsule Collider: This is a cylindrical shaped collider which has hemispherical ends. It is mostly used for character controllers.
Mesh Collider: It is a collider that matches the shape of the game object's mesh exactly. This collider type is useful for more complex shapes but comes at the expense of performance.
Terrain Collider: It is a collider which is specifically designed for the terrain objects.
In Unity, forces are what cause the Rigidbody
objects to move. There are several types of forces which can be applied to the GameObjects
.
Some of the most common forces are given below.
AddForce
: It is a continuous force that is applied in a particular direction. The actual effects of this force depend on the force magnitude and the mass of the GameObject
.
AddImpulse
: It is an instant force that directly changes the velocity of the object, independent of its mass.
AddTorque
: It is a rotational force that causes the GameObject
to spin.
These methods can be called from the
C#
scripts attached to theGameObjects
on which the force is to be applied.
Physic Materials in Unity are used to define the physical properties of the surfaces of colliding GameObjects
.
The main properties of materials are given below.
Friction: It is a force that resists the motion of one object over the other.
Bounciness: It determines how much an object can bounce when the GameObjects
exit collision.
High friction and low bounciness represents a rough surface.
Low friction and high bounciness represents an elastic surface.