Resources
Unity Course: The Complete Unity Guide 3D- Beginner to RPG Game Dev in C#
Introduction
A big part of working with the Unity game engine involves gaining familiarity with the Unity Rigidbody and its various properties. Rigidbody in Unity allows your GameObjects to act under the control of physics.
It allows you to interact with the physics of your objects and visualize how Unity is trying to simulate the physics of the real world. Considering the growing interests of Unity users all across the globe, we’ve discussed the working of the Unity Rigidbody in this video.
Discussed below are the properties of the Rigidbody that we’ve covered in the video.
Use Gravity
This property determines whether gravity affects your game object or not. If it’s set to false, then the Rigidbody behaves as if it’s in outer space. In the unity interface, you can use arrow keys to navigate your object in the given plane with the help of arrow keys.
If gravity is enabled, the object will fall off as soon as it crosses the plane's boundary. However, if it’s disabled, it’ll continue on its path uninterrupted. To see this phenomenon in action, you can navigate to [1:14] of the video.
Mass
This property of the Rigidbody is used for defining the mass of your object. By default, the value is read in kilograms. Different Rigidbodies that have a large difference in masses can cause the physics simulation to be highly unstable. The interaction between objects of different masses occurs in the same manner as it would in the real world. For instance, during a collision, a higher mass object pushes a lower mass object more.
This interaction between objects of noticeably different masses is exhibited in [3:58] of the video. A common misconception that rents users’ minds are that heavy objects will fall faster than lighter ones. This doesn’t hold in the world around us, the speed of fall is dictated by the factors of gravity and drag.
Drag
Drag can be interpreted as the amount of air resistance that affects the object when moving from forces. When the drag value is set to 0, the object is subject to no resistance and can move freely.
On the other hand, if the value of the drag is set to infinity, then the object's movement comes to an immediate halt. Essentially, drag is used to slow down an object. The higher the value of drag, the slower the movement of the object becomes. At [4:22] of the video, the effect of drag on a GameObject is demonstrated in detail.
Add Force
This property is used to add a force to the Rigidbody. Force is always applied continuously along the direction of the force vector. Further, specifying the Force Mode enables the user to change the type of force to acceleration, velocity change, or impulse. To learn how to add force to your object, refer to [5:34] of the video.
Users must keep in mind the fact that they can apply Force to an active Rigidbody only. If the GameObject is inactive, then AddForce will not affect. Additionally, the Rigidbody must not be kinematic as well. Once a force is applied, the state of the Rigidbody is set to awake by default. The value of drag influences the speed of movement of an object under force. This is explained in [7:40] of the video.
Angular Drag
Drag can be interpreted as the amount of air resistance that affects the object when rotating from torque 0. As was the case with Drag, setting the value of Angular Drag to 0 eliminates the air resistance over here as well.
However, by setting the value of Angular Drag to infinity, you can’t stop the object from rotating. The purpose of Angular Drag is only to slow down the rotation of the object. The higher the value of Angular Drag, the slower the rotation of the object becomes. This is demonstrated in [8:13] of the video.
Is Kinematic
When the Is Kinematic property is enabled, the object will no longer be driven by the physics engine. Forces, joints, or collisions will stop having an impact on the Rigibody. In this state, it can only be manipulated by its Transform.
Hitting objects under Is Kinematic brings about no change to their state as they can no longer exchange forces. This is explained in [11:05] of the video. This property comes in handy when you want to move platforms or wish to animate a Rigidbody with a HingeJoint attached.
Interpolate
Users are advised to use interpolate in situations where they have to synchronize their graphics with the physics of their GameObject.
As the unity graphics are computed in the update function and the physics in the fixed update function, occasionally, they happen to be out of sync. To fix this lag, Interpolate is used. To learn more about Interpolate, navigate to [11:50] of the video.
Collision Detection
This property is used to keep fast-moving objects from passing through other objects without detecting collisions. For best results, users are encouraged to set this value to CollisionDetectionMode.ContinuousDynamic for fast-moving objects. As for the other objects that these need to collide with, you can set them to CollisionDetectionMode.Continuous.
These two options are known for having a big impact on physics performance. However, if you don’t have any problems with fast-moving objects colliding with one another, then you can leave it set to the default value of CollisionDetectionMode.Discrete. Collision detection has been addressed in detail in [12:44] of the video.
Constraints
Constraints are used for imposing restrictions on the Rigidbody’s motion. It dictates which degrees of freedom are allowed for the simulation of the Rigidbody. By default, it is set to RigibodyConstraints.None.
There are two modes in Constraints- Freeze Position and Free Rotation. While Freeze Position restricts the movement of the Rigidbody in the X, Y, and Z axes, Freeze Rotation restricts their rotation around the same. This has been demonstrated in detail in [15:02] of the video.
Conclusion
Understanding Rigibodies in Unity and the various properties helps users navigate more freely around the Unity game engine. Plus, it adds an enhanced degree of precision to their game development caliber. If you don’t have the right guidance and resources at your disposal while learning about Unity Rigidbodies, then you risk developing an extremely flawed perception of the same.
This is where Eincode comes into the picture. The Complete Unity Guide 3D- Beginner to RPG Game Dev in C# offered by Eincode features among the most immersive and practical resources out there. Curated by experienced software engineer and freelance developer Filip Jerga, this course starts with the fundamentals. It progresses gradually to eventually take its subscribers through the journey of developing their own RPG game by using Unity 2020 and C#.