Rigidbody - Gr8-Tools/game-developer-roadmap-doc GitHub Wiki
Rigidbody in Unity
Total time: 6 hours
1. Key definitions and formulas
The Rigidbody component in Unity is used to simulate physics interactions for GameObjects. Some key properties of the Rigidbody include:
- Mass - Affects how the object responds to forces. Higher mass means it takes more force to accelerate the object.
- Drag - Applies air resistance which slows the object's movement over time. Higher drag slows the object more quickly.
- Angular Drag - Applies resistance to rotation similar to drag for movement. Higher angular drag slows rotation more quickly.
- Use Gravity - Determines if the object is affected by gravity. Enabling this property pulls the object downward over time based on its mass.
- Is Kinematic - When enabled, the Rigidbody is moved via setting position/rotation directly rather than through physics. Disabling allows full physics simulation.
2. Algorithms
The Rigidbody component uses physics simulation algorithms under the hood to calculate how an object moves and interacts based on applied forces and its properties.
The Rigidbody component exposes a number of useful methods for applying physics interactions programmatically:
Applying Forces:
- AddForce() - Adds a force at a given position in the object's local space. Takes a Vector3 force value.
- AddExplosionForce() - Applies an explosive radial force out from the object's position.
- AddTorque() - Adds torque to cause angular acceleration and rotation. Takes a Vector3 torque value.
Controlling Movement:
- MovePosition() - Sets the object's position directly without physics. Bypasses velocity/mass.
- MoveRotation() - Sets the object's rotation directly without physics.
- Sleep() - Puts the object to sleep so it stops simulating physics updates.
- WakeUp() - Wakes a sleeping object so it resumes physics simulation.
Getting State:
- velocity - Current linear velocity vector of the object.
- angularVelocity - Current angular velocity vector of the object.
- position - Current position in world space.
- rotation - Current rotation in world space.
Constraints:
- constraints - Allows adding joint constraints like hinges to limit movement.
3. Useful Videos
Time: 40 minutes
Time: 30 minutes
Time: 20 minutes
Time: 30 minutes
4. Useful References
5. Practice Tasks
Cube-game
- Reconfigure your "hero" control: use rigidbody methods to control forward-moving and rotating around.
Time: 2 hours
- Provide jumping: when user press "Space"-button the "hero" should jump. Jump shouldn't stop the hero moving process: if hero has had a velocity before jumping, it should complete moving in the same direction.
Time: 2 hours