Physics Objects (Rigidbodies) - Unity Official Tutorials
Estimated read time: 1:20
Learn to use AI like a Pro
Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.
Summary
In Unity's official tutorial on Physics Objects, the importance of using rigidbody components for moving game objects is emphasized. These components allow game objects to be influenced by physics, enabling features such as gravity, mass, drag, velocity, and collisions. The tutorial highlights the necessity of colliders for interactions, customization of gravity settings, and management of kinematic rigidbodies for static objects. Key elements like drag, angular drag, interpolation, collision detection, and constraints offer nuanced control over how rigidbodies behave, ensuring both efficiency and desired gameplay mechanics.
Highlights
Rigidbodies let objects interact with physics in Unity 🎮.
Adding a rigidbody allows objects to fall under gravity and have mass 🎯.
Mass affects collision reactions between game objects 🌍.
Drag simulates air resistance for game objects 🌀.
Angular drag affects rotational speed in physics interactions ⚙️.
Gravity settings can be customized for creative effects 🌌.
Kinematic settings optimize performance by limiting physics calculations 🚀.
Constraints can prevent objects from rotating or moving unexpectedly 🔒.
Key Takeaways
Rigidbodies are essential for physics interactions in Unity 🏗️.
Rigidbodies allow objects to fall, have mass, drag, and velocity 🌌.
Colliders are crucial for interacting with other physics objects ⚙️.
Custom gravity settings can create unique gaming experiences 🌟.
Kinematic rigidbodies enhance efficiency for non-physics interactions 🚀.
Interpolation settings help prevent object jittering 🌀.
Collision detection options ensure accurate physics interactions ⚠️.
Constraints can limit unwanted object rotations or movements 🚫.
Overview
Unity's tutorial on Physics Objects emphasizes the importance of rigidbodies for any moving game objects. Rigidbodies are crucial as they allow objects to be influenced by physics, such as falling under gravity or colliding with other objects. By applying a rigidbody component to a game object, developers enable it to react to forces and environmental factors, making interactions realistic and dynamic.
To effectively utilize rigidbodies, developers must attach colliders for interactions with other objects. The physics settings like mass, drag, and gravity can be manipulated to achieve desired effects. For instance, adjusting the mass controls collision behaviors while drag determines how quickly an object slows down. Developers can even modify gravity settings to simulate different environments or add unique gameplay mechanics.
Understanding rigidbody settings like interpolation and collision detection helps in smoothing object movements and ensuring accurate physics behaviors. The constraints feature allows developers to limit object rotations or movements, making it essential for games with specific interaction needs. Overall, mastering rigidbody settings in Unity ensures efficient and creative game design.
Chapters
00:00 - 00:30: Introduction to Rigidbodies In this chapter, the concept of rigidbodies in game development is introduced. Rigidbodies are crucial components that allow game objects to interact with physics by providing properties such as mass, drag, and velocity. These components enable objects to experience physical forces like gravity. For any game object to engage in physics-based interactions, it must have a rigidbody component attached, and a collider is also needed.
00:30 - 01:00: Adding Rigidbody and Basic Settings This chapter covers how to add a Rigidbody component to an object in Unity, which allows it to interact with other physics objects. Without a Rigidbody, objects remain static and will not respond to physics like gravity. By adding a Rigidbody from the Add Component button or the Component menu under the Physics section, the object can now fall under gravity and be influenced by physical forces. The chapter also introduces some basic settings of the Rigidbody, such as controlling the object's mass.
01:00 - 01:30: Mass, Drag, and Angular Drag The chapter discusses the concepts of mass, drag, and angular drag in the context of game objects. It explains how the mass of an object influences collision responses, with heavier objects reacting less to collisions with lighter ones. The concept of drag is introduced as a factor that affects how quickly an object slows down in the absence of other forces, analogous to air resistance, impacting the loss of linear velocity. Angular drag is similarly explained as affecting the rate at which an object loses angular velocity.
01:30 - 02:00: Gravity Settings The chapter discusses the concept of gravity in the Unity game development environment, specifically focusing on angular drag and torque for rotating objects. It explains the functionality of a checkbox option that allows game objects to be affected by gravity. Additionally, it guides users to the gravity settings located in Unity's Edit - Project Settings - Physics section, where gravity is represented as a 3-dimensional vector with a default real-world value of -9.81.
02:00 - 02:30: Customizing Gravity Direction The chapter titled 'Customizing Gravity Direction' explores the concept of modifying gravity's direction and intensity within a game environment. It discusses how different gravity settings can be implemented globally to create unique gameplay effects, such as low gravity for a platforming game or altering gravity's direction for puzzle elements. An example is provided where gravity is applied to the Z axis with a value of 5, causing objects like a power cube to be pulled towards the global Z axis. The chapter also touches upon the 'Is Kinematic' setting, which influences whether a rigid body responds to physics or remains unaffected.
02:30 - 03:00: Is Kinematic and Static Objects The chapter discusses the role of static and kinematic objects in a physics engine. It outlines that static geometry, which includes non-rigidbody objects, is only checked once at the start of a scene for efficiency. However, if a static object is moved, the engine has to re-evaluate all static objects, potentially harming performance. To mitigate this, kinematic rigidbody objects can be employed, which can be moved using the Translate function. These objects can influence others without being influenced themselves, optimizing performance.
03:00 - 03:30: Use of Kinematic Rigidbodies The chapter discusses the use of kinematic rigidbodies within the context of game development, particularly in games like Pong or Breakout. It uses the example of a paddle and a power cube with gravity enabled, illustrating the behavior of objects when gravity is applied. Without gravity, objects like the power cube do not fall. The explanation includes the setup of components using a power cube and a ball object to demonstrate how gravity affects them.
03:30 - 04:00: Rigidbody Interactions and Transform Movement This chapter discusses Rigidbody interactions and Transform movement. It explains the concept of making an object not affected by other objects using 'Is Kinematic'. The chapter further explores moving an object via its transform, using a simple script that employs the 'translate' function to move the object in its forward direction every frame while still allowing it to interact with other objects.
04:00 - 04:30: Interpolation and Extrapolation Settings The chapter discusses the application of interpolation and extrapolation settings in a physics engine to solve issues like jittering. It explains that the 'interpolate' setting is used to smooth the movement of a rigidbody based on its location in the previous frame. Conversely, the 'extrapolate' setting is used for prediction and smoothing based on an expected future position in upcoming frames. These techniques are crucial for ensuring smooth transitions and movements within a simulated physics environment.
04:30 - 05:00: Collision Detection Types The chapter discusses different types of collision detection methods in physics simulations: Discrete, Continuous, and Continuous Dynamic. The default method is Discrete, recommended unless specific issues arise. Continuous collision detection is suited for fast-moving objects interacting with static geometry, while Continuous Dynamic is for fast-moving objects interacting with other dynamic objects. Additionally, the chapter covers constraints within the rigidbody component, which allow for controlling movement or rotation of objects by physics.
05:00 - 05:30: Constraints and Final Example This chapter discusses the use of rotation constraints in a game development scenario. It specifically uses the example of a Tetris-style game where you might want to prevent the cubes from rotating as they fall. By adjusting the rotation constraints, these cubes can be made to fall without rotating. The chapter uses the specific example of a power cube falling onto a workbench, which is a rigid body with gravity enabled. By freezing the rotation within the constraints, the cube can be made to fall without rotating, demonstrating the practical application of rotation constraints.
Physics Objects (Rigidbodies) - Unity Official Tutorials Transcription
00:00 - 00:30 As a general rule, if you're going to have moving game objects in your game you should make sure that they are rigidbody objects. Rigidbodies are components that allow a game object to be effected by physics. They allow the object to fall under gravity, and have physics properties such as mass, drag and velocity. When we add a rigidbody component to a game object we often then refer to it as a rigidbody object. A rigidbody component is required for any physics based interaction, and the game object must also have a collider attached
00:30 - 01:00 in order to interact with other physics objects. Without a rigidbody our power cube will simply hover in mid air. But let's see what happens when we add one. Like any other component it can be added using the Add Component button at at the bottom of the inspector, or from the 'Component' top menu. You will find it under the Physics section. Now our object falls under gravity and can be controlled by the physics engine and any forces that are applied to it. Rigidbodies have numerous options. Firstly there are settings to control the mass,
01:00 - 01:30 drag and angular drag of the game object. The mass of the object effects how collisions are treated with the object. Game objects with a higher mass will react less when collided with a lower mass game object. The drag of a game object effects how quickly it will slow down without other interactions. Think of it like air resistance. It's used to determine the rate of a loss of linear velocity. Similarly, angular drag effects how quickly the game object will slow it's angular velocity, i.e. how
01:30 - 02:00 fast it is rotating. So for example if you're adding torque to the object to rotate it, the angular drag will create resistance to this force. The next option is whether or not the game object is effected by gravity. By enabling this checkbox we use gravity. Settings for gravity can be seen in the Edit - Project Settings - Physics area of Unity. As you can see it's a 3 dimensional vector which by default has a real world value of -9.81.
02:00 - 02:30 Because you can customise it globally here you could also create interesting effects Such as low gravity for a platformer or even setting it to a different axis as part of a puzzle game. For example, let's add gravity to the Z axis by a value of 5. And now the power cube is pulled towards towards the global Z axis. The Is Kinematic setting effects whether or not a rigid body will react to physics.
02:30 - 03:00 Ordinarily when a scene begins, all static geometry, meaning any non-rigidbody objects are checked once by the physics engine and not checked again for efficiency. However when you move a static object the physics engine must re-check all other static objects for the sake of accuracy, and this can be expensive to performance. To avoid this, Kinematic rigidbody objects can be used and moved via their transform by using the Translate function. This means that you can have physics objects that effect others but are not effected themselves.
03:00 - 03:30 An obvious example of this would be the paddle in a Pong or Breakout style game. In this example our rigidbody power cube has Use Gravity checked. When we press play, the object falls to the ground. We also have our round prop samoflange ball object, which has a similar component setup. If the power cube does not have gravity then it will not fall under it, but it will
03:30 - 04:00 be effected by other objects. If we don't want it to be effected by other objects we can use Is Kinematic. And as stated we can also move the object via it's transform. So we'll make use of this simple script, which uses the translate function to move it via it's forward direction every frame. And as you can see, the object still interacts with the others but remains a
04:00 - 04:30 rigidbody, so is constantly informing the physics engine of it's location and not forcing the physics engine to re-evaluate the entire scene. The Interpolate and Extrapolate settings are there to solve jittering. If you experience slight movement of your object when moving it via it's rigidbody, make use of the interpolate setting in order to smooth the transform movement based on the previous frame. And the extrapolate setting to smooth based on a predicted location in the next frame. The next setting is for the type of
04:30 - 05:00 collision detection. We have Discrete, Continuous and Continuous Dynamic. The default is discrete and unless you have any problems you should use discrete. Continuous is for fast moving objects that are interacting with static geometry. And continuous dynamic is for fast moving objects that are interacting with other dynamic objects. Finally the constraints section of the rigidbody component allow you to constrain movement or rotation of the object by physics. For example, if you
05:00 - 05:30 had a Tetris style game you might not want the cubes of your game to rotate as they fell in to place. You could constrain this using the rotation constraints here. In this example our power cube is falling on to the workbench. It's a rigid body that has Use Gravity checked. And as standard it falls like this. If we didn't want it to rotate as it falls we can freeze the rotation within the constraints. And now when it falls, no rotation. Subtitles by the Amara.org community