Techshop

Unity Tutorial 8 - Physics

There are a few things required for physics.

"Colliders" and "RigidBodies"

Colliders define the collision shape of an object. It is these that the Unity physics engine will use when it needs to work out if two objects have actually hit each other.

The ProBuilder tools will add the "Components" required for the 'Colliders' but it won't add the RigidBody.

A RigidBody is the part which actually does the physics simulation. Unless there is a RigidBody component on a GameObject it will just remain static. Objects can collide with it, but it won't react.

To make the 'coin' fall onto the 'floor' it needs a RigidBody adding to it.

Select the 'Cylinder'

Rename it "coin" … so we don't get confused in these instructions… in the "Inspector" at the top, rename it "coin".

At the Bottom of the Inspector, select "Add Component"

unity-tutorial-8-1.png#asset:604


Start typing "Rigidbody" and select the "Rigidbody" component when it becomes obvious.

You will now have the Rigidbody component added

unity-tutorial-8-2.png#asset:605unity-tutorial-8-3.png#asset:606


There's a few things to fix in the latest version of Unity that don't work out-of-the-box.

In the Inspector view above. In the "Mesh Collider" make sure that "Convex is ticked". This is telling Unity that the "Mesh", the collection of points and faces that make up the model, are, well, convex, they don't have angles over 180 degrees. It helps with the physics calculations.

For the "coin" object, right at the top, make sure "Static" is unticked. Again, this is an optimisation thing. Telling Unity the object is static in this way allows it to precalculate things, like lighting and physics. But we want the coin to move, so Unity will have to calculate these things on-the-fly.

Go to the "floor" object and untick "static". Same reasons applies to the floor.

Click play. The "coin" should drop onto the 'floor' object.

Video:

GIT TAG 005_AddPhysics

Unity - A simple tutorial < Unity Tutorial 7 - Creating some objects Unity Tutorial 9 - Pushing things & Animation >