Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last video we've looked at how to use a script to access the different animations of our game character and make it interactive. In this video let's take a look at another script that we can apply to make the camera follow our character around as he's moving. Luckily, we have another pre-built script for that. So in that Character Controller asset that we imported in the previous video I just want to look for this Third Person Camera script. I'm going to apply this just in the same way that we did with the controller script to the game character itself.
So I'm just going to left-mouse click- and-drag and just drop this right over our game character. So now if I click in the hierarchy on our game character it should be able to scroll down here in the Inspector and now see this Third Person Camera component that's attached to our character. So the camera script is going to be looking for which camera we wanted to control. So right now there's just one camera in our scene. So that's the main camera. So in hierarchy I'll just click on that, just left-mouse click-and-drag, just drop that right on the Camera Transform component.
Below that we have some settings in the script for the Distance away from the character we want the camera to be as well as the Height and some speed settings for how a camera moves and response to the character's movements. So let's just leave this on a default. I'll go ahead and hit Play and we'll see how this works. So we can see when I hit Play the camera actually moved automatically. If I just go ahead and click the W key and make the character walk, I can do W+Shift to make him run. We can see that the camera is following him around. Now we can make a couple of adjustments here.
One really cool thing about Unity is that even when the game is rendering we can make changes through the Inspector and those will update on the fly. So let's just adjust the Distance and the Height here. So I'll bring the camera little bit closer, maybe just drop it down a little bit, and I'll increase this Angular Smooth Lag so that will allow the character to kind of the scene more from the front and the side as he turns and not always from the back. So just click back in my Game view here. So, now as I move him around I get a little bit more of a frontal view when he's walking and it's not always just locked on the back there.
Another thing you might notice is the lighting. Remember, in a previous video we set up the directional lights. The lights always coming from this side of the scene regardless of where the characters standing, some scenes that might be okay. In this one, I want to make the lighting a little bit more even. So I'll stop the rendering right now and let's take a look back to our Scene view. One little trick I can do is actually just parent that light to the camera. So in my hierarchy I'll just click on a directional light and parent it to the camera.
So now basically if I select both I can see so the directional light is facing this way, the camera's also facing this way. So it's kind of like the light is always going to be perpetually facing the direction that the camera is facing. So let's go ahead and play and we should see a little bit nicer lighting. That's pretty good. So it's just more even. Again, that may not be exactly what you want in your scene. So you might do it a little bit differently, but that should work well for us. Again, I'm just going to click back on the character here and we will make some adjustments to the Distance and Height.
So one thing to note is when you make changes through the Inspector as the game is rendering, they won't stay permanent. They will only be applied while the game is rendering. So once we stop the rendering these changes that I'm making now will disappear. Then maybe let's drop that Height down a little bit. That looks pretty good. So again I'm just holding down right now S+Shift to make him run, and A and D will turn him side to side and Spacebar will jump.
So those are just some simple techniques to control cameras with the script. In the next video we'll look at Unity's built-in animation interface and how we can make our own animations within Unity.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 32789 Viewers
94 Video lessons · 22713 Viewers
78 Video lessons · 8943 Viewers
83 Video lessons · 8271 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.