Rigidbody
Inherits from: Component
The Rigidbody component adds physical properties to an object, allowing it to react to forces and torques, making it controlled by the unity physics engine. If you want an object to be affected by gravity, for instance, or if you want to be able to apply forces to it, you would attach a Rigidbody component to it. Rigidbody also keeps track of the object's position and orientation.
One common application of Rigidbodies is for creating objects that move and interact under physics control. On the other hand, you could also use Rigidbody for objects which move kinematically or which you want to move around the world but want to avoid intersection with other Rigidbodies. For a more detailed understanding, refer to the official Unity documentation.
Properties
The 'velocity' property accesses the velocity of the Rigidbody. It is essentially the speed at which the Rigidbody is moving through 3D space in your game, as measured in units per second, giving you control over the speed at which an object moves. For more about velocity, check out the official Unity documentation.
The 'angularVelocity' property describes the angular velocity vector of the Rigidbody in degrees per second. Angular velocity essentially measures the rate and direction of rotation. When working on rotating objects or adjusting spin on Rigidbodies this becomes very handy. Refer to the official Unity documentation for more.
The 'drag' property gives you control over the drag acting on the Rigidbody. Drag is a force that reduces the velocity of the Rigidbody making it decelerate over time as the force increases with speed. The ability to manipulate drag could help in emulating real-world physics like airflow resistance, slowing down your Rigidbody's linear movement over time. To learn more about this, visit the official Unity documentation.
The 'angularDrag' property controls the angular drag applied to the Rigidbody. Angular drag could be interpreted as your Rigidbody's rotational inertia or in simpler terms, resistance to changes in rotating speed. Modifying this could help in creating more realistic movements and spins. You can explore more in the official Unity documentation.
The 'mass' property allows you to alter the mass of the Rigidbody. The mass of an object is an important aspect in physics-based interactions and plays a crucial role when calculating how forces affect it. For example, giving an object a larger mass in the game would make it harder to push around. The official Unity documentation provides more insights about this.
The 'useGravity' property enables or disables the application of gravity on the Rigidbody. Disabling gravity might be useful for certain objects, like in a zero-gravity setting or while programming specific behaviors for an object, like a hover effect. To find out more, you can check the official Unity documentation.
The 'maxDepenetrationVelocity' property sets the maximum velocity the Rigidbody can have when resolving penetration. It's useful primarily for sleeping bodies that are directly moved or affected by other bodies that initiate overlaps. For details, see the official Unity documentation.
The 'isKinematic' property, when enabled, makes the Rigidbody stop responding to forces, effectively turning off its built-in physics engine. The Rigidbody continues to interact with other non-kinematic bodies and collide with them but will move only when directly controlled by its Transform. This is useful when moving objects under direct player or script control. Please consult the official Unity documentation for more information.
The 'freezeRotation' property, when enabled, causes the Rigidbody to stop rotating under the influence of external forces or impacts - its rotation only changes if directly manipulated. This property can be useful when you want to control Rigidbody rotation directly, or when simulating items that resist rotation such as wheels or gyros. Further details are in the official Unity documentation.
The 'automaticCenterOfMass' property determines whether the system should automatically compute the Rigidbody's center of mass. When this property is set to true, Unity calculates the center of mass based on the attached colliders. The official Unity documentation provides an in-depth understanding of this.
The 'centerOfMass' property helps manage Rigidbody's center of mass, a crucial factor in simulating physical behaviors. You can manually specify the local space position of the center of mass or let Unity automatically compute it. See the official Unity documentation for more on this.
The 'worldCenterOfMass' property accesses the global space position of the center of mass of the Rigidbody. This property is particularly handy when relying on the center of mass to calculate forces or torques that should affect the Rigidbody. The official Unity documentation provides a deeper understanding of this.
The 'automaticInertiaTensor' property enables or disables automatic calculations of the Rigidbody's inertia tensor based on its attached colliders. Disabling this allows setting custom inertia tensors, which can be beneficial for fine-tuning the rotational behavior of complex Rigidbody setups. For additional information, refer to official Unity documentation.
The 'inertiaTensorRotation' property specifies the rotation of the local space in which the inertia tensor is defined. This allows you to adjust the "shape" of the Rigidbody's mass. This property, in combination with inertiaTensor, can be used to fine-tune the rotational behavior of the Rigidbody. Detailed explanations are provided in the official Unity documentation.
The 'inertiaTensor' property determines the Rigidbody's inertia tensor, a measure of an object's resistance to changes in its rotational motion. Defining a custom inertia tensor can help simulate more complex rotational behavior. For more details, see the official Unity documentation.
The 'detectCollisions' property gives you control over whether the Rigidbody will detect collisions or not. In some cases, you may want to move a Rigidbody through a scene without triggering hooks like OnCollisionEnter. In such situations, disabling detectCollisions can be helpful. You can learn more from the official Unity documentation.
The 'position' property gives you access to the position of the Rigidbody. It can be used to directly set the position of the Rigidbody in world space, and can be of significance while operating in kinematic mode or when you want to bypass physics simulation. For more context, visit the official Unity documentation.
The 'rotation' property provides you with access to the rotation of the Rigidbody. It can be used to directly set the rotation of the Rigidbody in world space. It can be crucial while operating in kinematic mode or when you want to bypass physics simulation to manually rotate the Rigidbody. For an in-depth understanding, check the official Unity documentation.
The 'solverIterations' property allows you to adjust the number of solver iterations Unity performs for the Rigidbody. More iterations typically lead to more stable physics, but at the cost of extra computational overhead. Find more details in the official Unity documentation.
The 'sleepThreshold' property defines the minimum energy a Rigidbody must have before it can be put to sleep. When a Rigidbody is asleep, it won't register any physics updates until it's woken up, saving processing power. Visit the official Unity documentation to learn more.
The 'maxAngularVelocity' property sets the maximum angular velocity of the Rigidbody. It can prevent fast rotating objects from moving too quickly, which could lead to instability in the physics simulation. To know more about maximum angular velocity, check the official Unity documentation.
The 'maxLinearVelocity' property sets the maximum linear velocity of the Rigidbody. It is an effective way to cap the speed of fast-moving objects for stability or gameplay reasons. For more details, you can check the official Unity documentation.
The 'solverVelocityIterations' property sets the number of solver iterations used to solve velocity constraints. More iterations can improve stability but have performance implications. Additional information on this topic can be found at the official Unity documentation.
Methods
The 'AddExplosionForce' method applies a force to the Rigidbody that simulates the effect of an explosion at a given location. The force diminishes with increasing distance from the explosion source. This method can be used to create dynamic force effects in gameplay, like grenade explosions. Refer to the official Unity documentation for more details.
Parameters
explosionForce
number
The magnitude of the force of the explosion.
explosionPosition
Vector3The position of the explosion origin.
explosionRadius
number
The maximum distance from the explosion origin at which the explosion force is considered.
Returns
void
This method does not return a value.
The 'AddForceAtPosition' method applies a force to the Rigidbody at a specific position. Instead of applying the force through the center of mass, the force is applied at the specified position, creating a torque and causing the Rigidbody to rotate. This method is useful for creating precise scripted physics effects. For more information, refer to the official Unity documentation.
The 'AddRelativeForce' method applies a force to the Rigidbody relative to its coordinate system, as opposed to world coordinates. This is useful in situations where you want an object to push forward on its local axis, or similar operation relative to the object rather than the world. The official Unity documentation provides more details about force application in the local space of the Rigidbody.
Parameters
force
Vector3The vector to apply as a force in the local space of the Rigidbody.
Returns
void
This method does not return a value.
The 'AddForce' method applies a force to the Rigidbody in world coordinates. You can use this method to give an initial speed to a Rigidbody, or to simulate actions like a gust of wind or torrent pushing an object. You manipulate the speed and direction of Rigidbody through this method. For more context and examples, check the official Unity documentation.
Parameters
force
Vector3The vector to apply as a force in the global space.
Returns
void
This method does not return a value.
The 'SweepTest' method checks if a Rigidbody would collide with anything, if it was moved through the Scene. This can be used to predict collisions before moving an object or to find out if an area is clear from obstacles. The method provides information about what the Rigidbody would hit if it was moved through its environment. You can understand more about sweep testing from the official Unity documentation.
Parameters
direction
Vector3The direction in which to sweep the Rigidbody.
maxDistance
number
The maximum distance over which to sweep the Rigidbody.
Returns
Returns true if a Rigidbody collider is hit, and includes information about the object hit in a RaycastHit object.
The 'SetDensity' method forces the mass of the Rigidbody to adjust to the given density. This method is useful for recalculating mass after changing the mass of the object, especially when dealing with variable density fluids or building a physics puzzle. Read more about this in the official Unity documentation.
Parameters
density
number
The density to be set on the Rigidbody.
Returns
void
This method does not return a value.
The 'MovePosition' method moves the Rigidbody to the specified position by calculating the appropriate linear velocity required to move the Rigidbody to that position during the next physics update. This method is particularly useful when you want to instantly move a Rigidbody in response to player input or AI calculations. For further details, refer to the official Unity documentation.
Parameters
position
Vector3The target position for the Rigidbody in world space.
Returns
void
This method does not return a value.
The 'MoveRotation' method rotates the Rigidbody to the specified rotation by calculating the appropriate angular velocity required to rotate the Rigidbody to that rotation during the next physics update. It is commonly used for rotating Rigidbodies that are under the influence of physics. For more details, check out the official Unity documentation.
Parameters
rot
QuaternionThe new rotation for the Rigidbody.
Returns
void
This method does not return a value.
The 'Move' method simultaneously changes the position and rotation of the Rigidbody to match the specified position and rotation. This method affects the Rigidbody's position and rotation using physics and is therefore useful for moving objects under the control of physics. To understand more about it, take a look at the official Unity documentation.
Parameters
position
Vector3The new position for the Rigidbody in world space.
rotation
QuaternionThe new rotation for the Rigidbody.
Returns
void
This method does not return a value.
The 'Sleep' method is used to put the Rigidbody to sleep. When a Rigidbody is asleep, it won't register any physics updates until it's woken up, saving processing power. In most cases, you won't need to manually put a Rigidbody to sleep, as Unity does it automatically when objects come to rest. However, there may be times when you need to put a Rigidbody to sleep instantly, for example, when a game object should freeze in place. The official Unity documentation provides more insight into this topic.
Returns
void
This method does not return a value.
The 'IsSleeping' method checks whether the Rigidbody is sleeping or not. It can be used to confirm that a Rigidbody is asleep, for instance, before applying a force to it, since such changes would wake up the Rigidbody. If you want to know more, check the official Unity documentation.
Returns
boolean
Returns true if the Rigidbody is asleep, false otherwise.
The 'WakeUp' method is used to wake up a sleeping Rigidbody. Once woken, it will start receiving physics updates again. This is often useful when you want to instantly wake up a Rigidbody to reapply physics to it. For more on this, refer to the official Unity documentation.
Returns
void
This method does not return a value.
The 'ResetCenterOfMass' method resets the center of mass of the Rigidbody by calculating it based on the attached colliders. This can be useful if the Rigidbody's mass or shape has changed, and you need to recalibrate the center of mass. You can learn more in the official Unity documentation.
Returns
void
This method does not return a value.
The 'ResetInertiaTensor' method resets the inertia tensor of the Rigidbody by calculating it based on the shape of the attached colliders. This is similar to ResetCenterOfMass and is useful when the Rigidbody's mass or shape has changed. The inertia tensor influences how the Rigidbody's shape behaves when it rotates. Check out the official Unity documentation for more in-depth information.
Returns
void
This method does not return a value.
The 'GetRelativePointVelocity' function retrieves the velocity at which a point on the Rigidbody moves, relative to the Rigidbody, including any rotational velocity. This can be handy for numerous physical simulations or visual effects, such as calculating the directions of sparks when a rotating wheel hits an obstacle. More information can be found at the official Unity documentation.
The 'GetPointVelocity' method provides the velocity at which a point on the object is moving, including rotational velocity. This method is commonly used for visual effects or physics computations. For example, you might want to release a particle system at the position where a rotating wheel makes contact with the ground, and you want the particles to inherit the wheel's velocity at the contact point. You can explore more on this topic in the official Unity documentation.
The 'GetAccumulatedForce' method obtains the force accumulated on the Rigidbody over one physics simulation step. This is useful in certain effects or physics-based calculators that need to understand the amount of force being put on an object. For more details, refer to the official Unity documentation.
Parameters
step
number
The step index to retrieve accumulated forces for.
Returns
Returns the accumulated force for the given step.
The 'GetAccumulatedTorque' method retrieves the torque accumulated on the Rigidbody over one physics simulation step. Just like 'GetAccumulatedForce', this method is useful where you need to calculate the rotation effects based on the amount of torque applied on an object. The official Unity documentation provides additional context for this.
Parameters
step
number
The step index to retrieve accumulated torques for.
Returns
Returns the accumulated torque for the given step.
The 'ClosestPointOnBounds' method finds the closest point to the provided position on the collider's boundary of the attached Rigidbody. This method can be advantageous in numerous scenarios such as checking how close an object is to touching or hitting something. You can delve deeper into this topic in the official Unity documentation.
Updated 6 months ago