Create an empty scene to develop an animated door prefab that the character will trigger to open and close.
- [Narrator] In this chapter we're going to develop an animated door that will automatically open and close as the character walks through it in the game. To do that, let's start from scratch in a new scene, which is file, new scene. The scene has a main camera and a directional light by default. Let's create a ground plane object. Go to GameObject, 3D Object, Plane, then reset the transforms on that to move it to the origin point. Next, go to the models folder and you'll notice a new door prefab that I've supplied here.
This is a door.fbx file which was exported from Sketchup. Drag this into the hierarchy, and here is where we will develop the functionality of the door animating. It will open and close when it interacts with a character, so we also need a character in this scene. Let's save this scene as. Door Scene, that will be saved in the assets folder by default. Go to the assets folder and you'll see it right there.
Double click on the falling water scene to reopen that, and then let's get the character that we developed in this scene and bring it into the door scene. To do that we need to create a prefab on disk. Right now the character is in two different nodes, the third person controller and the free-lit camera rig. We need both of those items. So we need to put them in a single node. To do that go up to GameObject, Create Empty. Rename this, ThirdPersonCharacter and reset its transforms so that this empty object appears at the origin point underneath the character's feet.
Then select the third person controller and the free-look camera rig by holding down the shift key and drag these nodes and drop them into the third person character. They should become indented like this. This indicates that these items are now children of the third person character node. Now go to the models folder and drag the third person character from the hierarchy into the models folder like this. That will create a prefab on disk.
Down here it says ThirdPersonCharacter.prefab. So it's a file that is now portable. So I can go back to my other scene. Let's first save this scene, and this asterisk means that these scene is not yet saved, so I'll choose File, Save Scenes, then I'll go to the assets folder and double click on the door scene to reopen that. Go to the models folder and drag the third person character into the hierarchy. And then move the character back.
Let's take a look at that. I think he needs to go over a little bit in the red direction too. And let's test drive the game. Now I can walk forward and I go right through the door. Also, we're actually viewing the character right now through the main camera rather than the free-look camera rig. So I will disable the main camera up here and test drive the game again. So now we have the more familiar look over the character's shoulder.
So we need to fix the door so we're not able just to walk through it like that. Open up the door here in the hierarchy. Expand frame and glazing and select Mesh 3. I'll zoom in on the door here. The door needs a collider. Click Add Component, Physics, Box Collider in this case because the geometry is not a sphere or capsule. Box will work just fine.
The green box assumes the volume of the frame and glazing object, and you can see that in green. Here you can toggle it off and on. When the collider's on, it will provide the illusion of solidity. So now I can't walk through it. That's good so far, but we need another collider on the door to act as a trigger mechanism that will trigger the animation ultimately.
To add this, I want to be sure to add this secondary collider to the door itself so that it will animate not only the frame and glazing object, but also the handles and locksets on each side of the door as well. So with this top node selected I'll add another component. Physics, Box Collider. And this time because I'm assigning the box collider to the empty game object door, it doesn't know what volume to assume, right? So it's coming in as a one meter cube at the origin point of this object.
So what we now need to do is edit the collider and change its shape so that it matches the shape of the door. You can do that by moving these handles. To really see what we're doing here, it's necessary to view this from the front view, so I'll click on this cone here and then click on the word to go into isometric mode, and then just navigate, get a better look at the door here. Now I can adjust the handles in an easier way where I can see how that relates to the geometry.
It doesn't have to be perfect, just close. I'll orbit around, go back into perspective. And now what I want to do is provide a volume in front of and behind the door that will act as a trigger mechanism, and that will allow the character to trigger the animation ultimately. I'll hold down the option or alt key while I'm dragging the handle to move the opposite handle symmetrically.
So I want to create enough volume in front of the door so that the door can swing open and the character won't hit the door. So something like this might work, maybe a little less. So I'll turn off edit collider mode and click Is Trigger, and this is very critical because this collider, we don't want it to act like a wall that we run into, no, we want it to act as a trigger that we can script to connect with the animation of the door. So that's all we need to do, let's test drive the game one more time, but we're not going to actually see anything happen with the trigger yet, that's something we'll have to add in the next few videos, so let's go ahead and save our scene.
Instructor Scott Onstott starts with a SketchUp model that he cleans up and imports into Unity, where he creates the first-person and third-person characters and cameras needed to explore the model. Then he shows how to improve the building's appearance by sculpting and texturing the surrounding landscape, and populating it with trees, moving grass, and flowing water. Next, he demonstrates how to animate and script doors so they automatically open as the character approaches. Then real-time lighting is baked into textures for greater efficiency and an overview map is added to keep the player oriented within the overall floorplan. Finally, Scott tests and deploys the final interactive visualization for desktop and the web. No plugins are required to view the results! Follow along to build your own version of the project and strengthen your Unity skills.
- Importing a model
- Creating a first-person and third-person characters
- Scripting the walk
- Swapping characters
- Adjusting lighting
- Sculpting terrain
- Painting textures
- Refining materials
- Animating doors that open and close
- Configuring an overview map
- Baking lighting into textures
- Deploying the game to different platforms