Welcome to 3D Interactions and Navigation, the third course in the Unity Certified Programmer Specialization from Unity Technologies.
This course will help you prepare for the Unity Certified Programmer exam, the professional certification for entry to mid-level Unity programmers. Unity is used to create real-time 3D applications for many industries, including video games, automotive, film, training, and more. In this course, you will be challenged to solve realistic Unity programming problems that are aligned to topics covered on the exam.
In the third course, you will start development on a new 3D application: Stealth. In this application, a 3D stealth-style game, the user guides a 3D character through a maze-like environment filled with hazards in an attempt to avoid detection. In implementing this application, you will review and practice many of the skills covered in the exam, including setting up navigation meshes and agents, working with 3D character animation, scripting camera movement, and more.
This is an intermediate course, intended for people who are ready for their first paying roles as Unity programmers, or enthusiasts who would like to verify their skills against a professional standard. To succeed, you should have at least 1-2 years of experience programming interactive applications in Unity. You should be proficient at programming in the C# language and familiar with Unity's scripting APIs. You should have experience in the full product development lifecycle, from concept to launch (and beyond). And you should understand multi-platform development, including deploying applications to XR (AR and VR) platforms.

Reviews

Filled StarFilled StarFilled StarFilled StarHalf Faded Star

4.5 (40 ratings)

5 stars

70%

4 stars

18%

3 stars

5%

2 stars

3%

1 star

5%

From the lesson

Character Animation and Camera Control

The enemy agent can now move around the level, but we need to let our a player character or avatar move. In this week's lessons, you'll implement character animation and a sophisticated camera system to track it.

Taught By

Jeremy Gibson Bond

Unity Technologies

Transcript

Hi everyone, I'm Jeremy Gibson Bond, and welcome back to the Unity Certified Programmer Exam Preparation Course. In this video, we're going to be looking at your next challenge, which is a camera control challenge. Now, there are a lots of different kinds of cameras that you encounter frequently in Unity games. One would be like a Top Down 2D camera, like we used in the AsteraX game in Courses One and Two. Another would be an Anchored Camera kind of in the corner of a room, you see this in games like Resident Evil and the Adventure Tutorial created by Unity, you can find on the Asset Store, from which we got a lot of the assets for this game. You also see it in the first challenge, the enemy navigation challenge, where I had that camera in the corner that sort of followed the enemy as it moved. Another common camera that you see is a First Person Camera. Those are usually done using sort of a layered system in the hierarchy, where you have one game object that rotates left and right and other one that actually handles rotating the camera upside down that is a child of the first one. What we're going to be looking at in this challenge is a Third Person Camera. So, we're going to be modifying the Stealth player camera code that you've had for the previous challenge, the animation challenge and really enhancing it to work in a way that's going to be better for our players. So, let's take a look at how it actually works in the game with the finished version first and I'll describe the various bits of it and the minutia of the details and how it works. Let's take a look. Okay. So, here we are in Unity and now let's take a look at the way this camera works. So, I've got my player down here and you can see that you know, she runs around and the camera follows her just like we've been seeing before. Here's where it gets interesting. So, if I walk up to an edge and go into cover, which you set up in the last challenge, when I get near the edge you'll see this green line to her left turns red and that means there's nothing behind it anymore, it's not running into a wall and you can see that the camera zooms in. This is how the camera worked in Metal Gear Solid and it's kind of become a standard for Third Person 3D Stealth Games. Now, you'll note that when she reaches the edge, the closer line there also turns red and that's how the third person wall cover movement script knows to stop her from moving. She does walk into corners and just keeps walking in corners. That's fine, I really just wanted to set this up for the camera movement there. All right. So, when she walks into a wall that is to her side here, you can see that she moves down and then again the camera rotates. Another important thing to note here is that when she is in the near camera mode and it's kind of peeking around the corner, the camera is offset to her side to more easily see down that hallway as you can see here. If I move her over to this side you can see that it's offset now to the right instead of the left to make sure that it's able to look down the hallway. This works very well when we walk in the corners to the side and you see that, again, it's offset properly. So, that's an important part of this camera. So, as you saw when the player goes to a wall to her side, the camera pans to that side. Now, this also means that to be consistent when she goes down and moves towards an edge, the camera needs to look that way as well. So, this provides an interesting challenge, which has to do with how the control should work when the camera is reversed and we're going to talk about that a little bit later because that's going to be your bonus challenge. But first let's dive into the Third Person Wall Edges Script, which is the script that puts these nice Gizmos up showing us whether she's close to the edge and all that and it is the script that you're going to read from using your stealth player camera to understand sort of how the camera should move relative to the player. So, let's dive into that script now. Here, we are in the third person wall edges script, there's a lot going on in here, but the core thing that you need to know about those edges is right here at the top. So, wall L and wall R are the two lines that you saw that are closest to her. If wall L is true, then it's sensing a wall there just immediately to her left. Zoom L and zoom R are the two that are further out to the sides and if they are true, then it's sensing a wall further down. So, when she is positioned such that wall L is true and zoom L is false, that means that the camera to zoom in to her left and go to the neater left position. If she's positioned such that wall R is true and zoom R is false, then the camera again, should zoom in on her right side because that means that the wall is there close to her but it's not there far away from her. Now, to access the wall L and wall R, zoom L and zoom R from the third person wall edges, you need to get a reference to it somehow. Happily, this is already done for you in the stealth camera. So, if you look at the stealth player camera under update, you can see that line 54 says, coverInfo equals playerInstance.GetCoverInfo, and if we go to the definition of that method, you can see that this pulls the coverInfo about whether or not you're in cover as well as the wall L, wall R, zoom L and zoom R from the third person wall edges script. So, this is the easiest way to get that info, I just wanted to show you in the wall edges, so that you understood what that info meant. You also are going to need to pay attention to kind of her facing and you get that from the inner cover value on third person wall cover. So, when I am in cover to the North, that is zero, cover to the East or in the positive X direction is one, cover down is two and finally, cover to the left, to the negative X direction is three. So, I guess from your perspective looking, it's zero, one, two, three. So, that gives you the facing and between that and the information from the third person wall edges, you should be able to determine where the camera should be in order to succeed at this challenge. So, speaking of which, let's look at the bonus challenge. So, I've added another tool to my kind of folder of tools here called WatchArrowKeys. I'm going to drag it onto the player and what this allows us to do is see what's going on with the arrow keys. Now, we can see it here with up, down, left and right and I've also set it up to wear it Debug.draw array to draw a cyan line in the direction of keys that are held. So, I'm going to press play, I'm going to move the player to the middle here and then we can see what I'm talking about. Okay. So, here's the player and you can see that I've got the cyan arrow when it is held in certain directions and I'm holding up and you can see up is held and then I hold L and it creeps the left, I hold R or the right arrow and it creeps to the right. Now, this gets much more complicated when I move down a little bit. So, let's go and look here at what's happening in this area. So, now I'm going to move my character to the back wall and we'll call this the back wall, and she's in cover against the back wall. If I hold left, she's going to move to her left and then the camera's going to flip around, flipping in the direction that left is, but you'll see that she continues moving to her left until I release the key. Now that I've released the key and the camera is still facing in this direction, you can see I'm holding the down key but not the left key, when I press left now, it's based on where the camera is facing when she starts moving and it will stay that left until I release left again. So, watch again what's happening with the left checkbox there and the left arrow that's happening there from the debug.draw array. I hold left and even though the camera moves left, it's still to the character's left, but now that I've released left. Now, if I push right, it'll actually go towards the right edge from our current camera view and if I push left, it will move away from that again, until I release the key which then tells it that it can switch to the direction that we're currently seeing with the camera. That's the challenge and this is done in a lot of games that handle camera this way. You actually saw this as far back as games like Final Fantasy Seven, where when the character moves through a doorway, that causes the directions to switch. So, if the doorway is on, I guess from your perspective the doorway's on the right side of the screen and you walk through that doorway by pushing up because you're going towards it up on the right side of the screen. Then the character comes out of a door here facing this direction. If you still hold up, the character will continue moving in that direction until you release the key because otherwise, it up went through it was always up in the scene than the character we go up through this door and then immediately come out and go back up through this door with the player still holding the key in the same direction, was still holding the control in the same direction. So, it's really important That you maintain consistency of movement even if the camera changes until the player releases the key at which point the player then thinks again about how she's going to control the character and that's when you can serve reset with the keys me. So, for this bonus challenge, you're going to need to change code in the third person wall cover class. This is inside of the method GetCreepValue. What this method does is, as you can see it takes access information horizontal and vertical and then returns the proper access based upon whether the player is in cover or not. So, when the player is in cover which you can see down here, if the cover is forward cover right, in the positive z direction then it returns h if it's cover to the sides, like to the right side, it's negative v, to the left side it's v, but back cover, that's where you want to replace this line that just returns negative h with a line that really pays attention to all the stuff we just talked about, but the camera switching, but the control not switching until the player releases the key. So, that's where you want to change that. Other than that, everything you're going to do really should be in the stealth player camera unless you're going to do something really fancy that I didn't think of. All right. So, I hope you enjoy this challenge, it might take some trial and error to get right, but I think it's a really good one and I think you'll have some fun with it. I will see you in the next video. Thanks.

Explore our Catalog

Join for free and get personalized recommendations, updates and offers.