RigidBody ********* Intro ===== A **Rigidbody** in Unity is a component that enables a GameObject to react to physics, like gravity and collisions. It allows movement through forces making the object behave more realistically in the game world. Here are some typical configurations using a RigidBody: .. hint:: * Blocking + Moving * Object moves and responds to gravity or impulses, can collide and bounce with other elements * Useful for: moving car, falling domino, basket-ball * Set: **Collider + RigidBody** * Function: void OnCollisionEnter(Collision collision) * Blocking + Immobile * Object doesn't move, but other objects can bump into it * Useful for: walls, floor * Set: **Collider only** * Function: None .. warning:: Beware, when the trigger of the collider is activated, this implicitly disables the rigidbody of the gameobject. .. warning:: In previous project, we have moved objects using the translate or rotate function. Exercise ======== Basic setup ----------- We begin our study by adding a RigidBody to the sphere. * Create a cube and and assign it a color * Scale the cube to create a ground * Select the sphere * In the Inspector, click on the button *Add Component* * Select RigidBody * In the RigidBody section, check: **Use Gravity** .. image:: usegravity.png :scale: 50% .. image:: fall.png :scale: 35% * If you want the camera to shoot the same view as the scene view * In the Hierarchy, select the camera * Right click and select Align With View * Enter Play mode .. image:: fall.gif :scale: 40% What happened? * The sphere has a *Rigidbody*, moreover it is affected by gravity so it falls * The ground don't have a *Rigidbody*, it's a static object, it cant move * Both the sphere and the ground have a Collider, allowing them to come into contact, which stops the sphere's fall Simulation ---------- We add some new elements to the scene; try to reproduce the scene below. Some hints: * Analyze which object has a RigidBody: is the object moving or not? * Detect which object is affected by gravity: it is falling or not ? * Enable all options correctly .. image:: bascule.png :scale: 48% .. image:: vidbascule.gif :scale: 60%