Add physical properties to 3D GameObjects

Tutorial

foundational

+10XP

30 mins

16759

Unity Technologies

Add physical properties to 3D GameObjects

In this tutorial, you’ll explore some visual and physical effects you can achieve in a 3D Scene. You will:

  • Create and configure a new Material to add visual properties to a GameObject.
  • Create and configure a Physic Material to add physical properties to a GameObject.
  • Configure the directional light.

Materials

1. Overview

Materials are components that define the surface characteristics of objects, and how those surfaces interact with light. In each new 3D Scene, directional light is included to simulate the sun. In this tutorial, you will create a simple Material to change the visual appearance of a GameObject, and use a Material to change physical properties as well. The directional light will bounce off the GameObject with its Material to create a visually realistic effect.

2. Before you begin

The visual appearance of the Material will come from an image file. You can download the file used in the steps below, Herringbone_Brick_baseColor.png, by selecting Tutorial Materials in the masthead at the top of this tutorial.

3. Import an image file

1. To make your Unity windows match the examples below, right-click the tab of the Project window and select Two Column Layout if it is not selected already. The folders of your project appear in the left column, and the contents of the selected folder appear in the right column.

2. Right-click the Assets folder in the Project window and select Create > Material.

3. Rename the new Material as BrickMaterial. The preview of the new Material is a 3D sphere, so that you can see how light interacts with the Material at many angles. When you select the Material in the Project window, a more accurate preview appears in a resizable pane of the Inspector.

4. Download the file Herringbone_Brick_baseColor.png from the Files listed at the top of this tutorial.

5. To import the file into the project, you can simply move the downloaded file to the Assets folder for this Unity project, which is represented in the Project window. To see the contents of the Assets folder in your file explorer, right-click the Assets folder and select Show in Explorer.

6. In your computer’s file explorer, move the Herringbone_Brick_baseColor.png file into your Assets folder. When you return to Unity, you will see its icon.

4. Create the Brick Material

1. Select the BrickMaterial.

2. In the Inspector window, select the circle icon next to the Albedo property. Albedo encompasses the reflective properties of the Material, based on a solid color or an image.

3. Select Herringbone_Brick_baseColor from the list of images in your project.

The image is now applied to the material as the Albedo map, and will appear in the Material preview.

4. Create a new cube GameObject in the Scene.

5. Drag the material onto the cube in the Scene view.

6. The cube now displays the brick Material.

7. To change the scale of the Material, select the cube, open the BrickMaterial Component in the Inspector, and change the Tiling X and Y properties. Smaller numbers make the bricks appear larger.

5. Adding a Physic Material

Earlier, you added a Rigidbody component to a GameObject to give it physical properties. You can also add additional physical characteristics with another type of Material called Physic Materials. With Physic Materials, you can make an object bounce and change its friction and drag properties.These properties take effect when the object is under the effects of gravity. Physic Materials don’t change the visual properties of the GameObject’s mesh.

1. In the Project window, create a new folder called Materials. Right-Click in the Materials folder in the Assets window and select Create > Physic Material.

2. Rename the material to BouncyBall.

3. Select the new Physic Material.

4. Change the Bounciness value to 1 in the Inspector window.

5. Select the cube. In the Inspector window, select Add Component and add a RigidBody component.

6. Your cube should already have a Box Collider component added to it. This component is automatically added when you create the cube in the scene. Drag the new Bounce physics material you created earlier into the Material slot in the Box Collider component.

7. Run the game. Your cube should now fall to the platform and have a bit of bounce when it hits the floor.

8. Experiment with your bouncy cube: try rotating it, duplicating it, and making cubes fall on top of each other!

6. Adjusting the Lighting in the scene

In a new 3D Scene, an object named Directional Light is included to simulate sunlight. You can manipulate this light with transform tools like any other GameObject.

1. Select the Directional Light in the Hierarchy window.

2. Change the rotation of the light using the transform tools Move (shortcut key “w”) and Rotate (shortcut key “e”). Directional lights simulate a light source that bathes the entire scene in light coming from a specific direction. Changing the position of the light will not have an influence on the scene but changing the rotation will change the angle of the light in the Scene. Take note of how the sky and ambient light changes as you change the angle of the light.

Directional light is just one type of light. If you are interested in other types, see Types of light.

7. Next steps

In this tutorial, you have seen how Materials and light work together make GameObjects look visually realistic. You also used a Material to add physical properties to a GameObject, and you adjusted the directional light. In real-world applications, however, you will need more than spheres and cubes. In the next tutorial, you will see how to get more sophisticated GameObjects into your projects without having to build them from scratch.

Complete this Tutorial