This is part 3 of a tutorial series in creating animated shorts with Unity 3D. In part 1, we configured Unity and downloaded the needed packages and plugins. In part 2, we fixed a bug in the code and configured the lighting for real-time rendering. In this tutorial, we are going to tweak the lighting and reflection, then animate the character.
Let’s help Unity handle reflections better by adding a Reflection Probe.
Move your view so that you are looking down on the scene. Click on GameObject > Light > Light Probe.
Move the light probe so that it covers the area in front of the red cube. If you need to resize the probe, click on the Edit Light Probes button in the Inspector and drag the edges until the area is covered.
Once you have the area covered, use CTRL-D to duplicate the probe and place the new probe in front of the other two cubes.
Now we are showing a red reflection on Adam.
To improve the reflection on to Adam, we can add reflection probes to each of the cubes. Use GameObject > Light > Reflection Probe and position a probe over each light area. You can adjust the size of the probe by clicking on the Edit Bounding Volume button in the Inspector and dragging the squares that appear on each side of the bounding area. Once you have the first one configured, use CTRL-D to duplicate the Reflection Probe and move it over the remaining cubes.
Finally, select the Plane, and the three cubes in the Hierarch panel. In the Inspector Panel, click on Static in the top right corner. Make sure that Contribute to GI & Reflection Probe are both selected.
Once your system is finished baking the new lighting configuration, you should see nice reflections from the cubes on Adam.
With the lighting configured, we are ready to move on to animation.
Just as in other programs where we create animated sequences, we will need a timeline to associate with the animation. To add a timeline, click on Window > Sequencing > Timeline.
I placed my timeline in the same panel as the Project assets and console.
Currently, the Timeline is blank. We need to create a file to associate with the timeline to record the activities.
Timelines are associated with game objects. Select Adam from the Hierarchy, then click the Create button that appears in the Timeline.
Unity will open a dialogue box to create a file for the timeline. Use the default filename, but I recommend saving the file to the Assets folder instead of in the Adam folder. Click Save to create the file.
The Timeline will now show an empty timeline for the Adam character.
One of the great things about using Unity for your animation tool is that you can use generic animations with properly configured characters like Adam.
Let’s get Adam moving. Right-click on the dark-grey timeline area by Adam. Select Track Offsets > Apply Scene Offsets.
This will force the new animations that you apply to keep the scene settings that you have already configured (like Adams location and orientation). Believe me, this will save you a lot of frustration!
Right-click on the blue area again and select Add From Animation Clip.
The Animation panel will open. Select the Adam Walk from the Select Animation Clip panel.
Dragging the white line in the Timeline will allow you to scrub, or see, the animation process of Adam walking across the scene.
You can have Adam walk further across the scene by dragging the end of the Adam_Walk to the right with your left mouse button. This will cause the animation to loop and maintain Adam’s new location in the scene. Let’s have Adam walk to the beginning of the last cube by stretching the Adam_Walk in the Timeline. You can check how far Adam walks by using the white medallion to scrub along the timeline.
For the next portion of the animation, I would like Adam to turn to the left and walk to the front of the scene. There are several different turn animations included in the Select Animation Clips. Right-click on the Adam Timeline, click on Add From Animation Clips and select one of the left turns. I chose HumanoidWalkLeft clip.
If you scrub into the turn clip, Adam jumps back to the original starting point. To correct this, right-click on the HumanoidWalkLeft clip that you just added and select Match Offsets To Previous Clip. Now Adam will continue walking from his last position in the Adam_Walk cycle.
To get a clean transition between clips, you can slide the HumanoidWalkLeft on to Adam_Walk. This integrates, or blends, the two different animations so that your transition looks natural.
If the speed between the two animations does not match, you can adjust the second animation by changing the Speed Multiplier up or down in the Inspector with HumanoidWalkLeft selected. You can also adjust the Blend Curves if you are familiar with working with animations. If not, don’t worry, we will talk about Blend Curves in a later tutorial.
To get Adam in the position that I wanted, I used the HumanoidWalkSharpRight to position Adam in the center of the stage toward the front. Remember to use the Match Offsets to Previous Clip!
If you haven’t saved your project lately, now might be a good time.
To finish the positioning, add another Adam_Walk to transition Adam from the sharp right turn to a normal walk. Finally, add HumanoidIdle to bring Adam to a stop. Remember to use the Match Previous Clip Offset for each and blend appropriately.
That takes care of the basics of animation. While there are many more areas we can explore (importing mocap animations (bvh or fbx), connecting to Blender or Maya, using the animation tools, etc), we need to move on to using the camera.
Anyone who has worked with traditional cameras on a low-budget (i.e. student) project knows that one of the most time-consuming parts of the project is having to shoot the scene many times so that you can get different camera angles for your editing.
Shooting a scene with one camera angle and one shot is risky. Unless your director of photography and director are incredibly talented, it is best to use multiple cameras (or takes) to get the scene cuts that you need for editing.
With Unity, we can have as many cameras as we need to tell our story. Plus, since we are setting and moving the cameras as we develop the scene, much of the editing is handled at design time.
Our goal with the camera work is to use the Cinemachine to create a basic camera movement that follows Adam as he walks across the stage.
To add our first camera, right-click in the area under Adam in Timeline and select Cinemachine Track. This will add a new animation sequence in the same timeline. Right-click under Adam_walk and select CinemachineShot. Congratulations, you just created a virtual camera. Expand the CM vcam1 to the same length as Adam’s first walk segment. Now select CinemachineShot.
In Inspector, click on the Create button under Cinemachine Shot.
You need to select a Look At and a Follow for the camera. The Look At, as you might have guessed, keeps the camera focused on a target object, such as Adam. Now, Adam is actually fairly large. You can specify Adam, or you can be nuanced and look at a part of Adam such as his head or chest.
The Follow tells the camera to keep a specific distance from an object. In our case, the Look At and Follow are the same.
Of course, there are many more settings we can adjust with the camera, but we will keep it relatively simple for now.
Adjust the camera’s location so that it is in front of Adam, looking at him straight on. You can do this by clicking on the CM vcam1 object in the Hierarchy and moving the camera in front of Adam’s walk path.
Check the camera shot using your scrub tool, you can see how the camera will move as Adam walks. To see what will be recorded, you can switch to Game mode ( the Game tab at the top of the screen) and continue to scrub the Timeline. Of course, you can add more cameras to the scene if you would like to give different angled shots.
To record the project, select Window > General > Recorder > Recorder Window. This will open the Recorder Panel.
Click Add New Recorders and select Movie.
You can set your Target Frame Rate (default is 30). Remember that if you are targeting TV or Film, to select the recommended frame rate for that platform. If you are targeting YouTube for your distribution, they accept 24, 25, 30, 48, 50, or 60 frames per second.
Be sure to set the file name and destination folder. The default location is your project folder/Recordings. You can set the recorder to do different takes to allow experimentation. You can also set the Output Resolution and Aspect Ratio.
Capturing the Audio is up to you. If you didn’t add any audio to the project, it doesn’t make sense to include it here. Most add audio in post-production with your compositing software.
When you are ready, click the red Play button or the Start Recording button to start recording.
The scene will run (and record). When you are finished watching Adam idle, click the Stop Recording button. The movie file should now be in your project/Recordings folder.
And there we have a basic recording. In future tutorials, we will explore post-processing, different types of cameras, and more real-time CGI awesomeness!
Here is the first 3 parts of this tutorial on YouTube:
Dr. Burton is a teacher and professor with over twenty-five years of experience teaching learning in virtual worlds, game design, CGI, Information Technology, Computer Science, and MIS