Hello, welcome to this lesson in Unity. In these lessons, you will learn how to create all your 2D gameplay in Unity. Community Hub, open the platformer project, open the Level 1 scene, to review where we are at, play the level. This is called game testing, and you should check or play your level frequently to make sure your settings and code are correct, and it makes it easier to fix bugs as they come up. Stop play. If I move to the left, using the A or the left arrow, the player moves and stops at the wall by design. If I press the space bar, the player jumps. However, if I continue to move my player to the right, it goes off screen. And that's not good. Stop play. It seems we need a camera to follow the player. The most basic way to do this is to simply parent the camera to the player in the hierarchy, by clicking and dragging the camera on top of the player. The camera becomes the child of the player, now we play the level, and for the most part this seems to work. Cameras follow on the player. But it would be nice that the camera can follow the player smoothly. We can do this in code that we can attach to the camera. Stop play. Unparent the camera by clicking and dragging down, play the level again and confirm the camera is not moving. Stop play. Open the Scripps folder, and create a new C-sharp script and name it CamFollow. Select the camera in the hierarchy, and drag the CamFollow script into the inspector. As you can see by now, you can build your game level, controls, and actions a little bit at a time. You could have one script to control everything, but that can be cumbersome to debug if there's many lines of code. Open the CamFollow script, remove the update and start methods. After the first curly bracket, press Enter to make a new line, and type in our first variable. Public Transform Target. Targets are a variable name, and so have a transform type. This will allow us, in the editor, to drag any game object in as a target to follow. Next, we'll add a fixed update method to update the target position and set it to the camera position. Fixed updates used when using physics. It enter a couple of times, and type in private void. Fixed update, inside the curly brackets, type in transform.position. This would be the transform of the object the script is attached to. We'll set that equal to the target position. Save the code, minimize visual studio, and the Unity editor has selected main camera. You'll see now it's a slot for a target, so we're going to drag our player into that target. What we are seeing is what the camera sees at the exact position as a player. Although we are working on a 2D platformer, all game objects in Unity are still in 3D space. Game elements move only in X and Y, but the camera needs to be distanced away in the Z direction, so we can see an area of the level. Stop play, with the camera selected, note in the inspector, the default position for the main camera is 0 on X and Y, but minus 10 units in Z. We change this value to 0, you can see in the blue background in the preview window. Change it back to minus 10, we'll need an add an offset value to our code, so we can adjust the camera position away from the player, as well as the ability to fine tune the camera position in X and Y. Open the camera file script, after the target variable, click enter, to make room, and type public vector 3, now we're working 3 dimensions, and the variable is called offset. Because it's public, we can adjust the 3 values in the editor. Now change the code in a fixed update method by adding plus offset. To set the offset to the target, save the code, minimize visual studio, select the main camera in the hierarchy, in the inspector we already know we need to change the Z value in offset to minus 10, so type that in. Play, now it's working fine, we can see our level and our character, the camera is moving with it, but it'd be nice if we get adjusted, so at the beginning of the game, we're not seeing the blue area, we can do that by clicking and dragging over the X or Y value under the offset, and adjusting how we want it, and then click over the Y, and one more adjustment here. Unfortunately these settings will return to the original settings when the play stops, but we can copy and paste the values, right click over offset and choose copy, stop play, right click over offset again, click paste. Now those values are added, we play again, now everything is lined up well nice, but this doesn't look or act any different than when we just parented the camera to the player, so why bother using code? The code allows us to further adjust the offset, if we want to change it a bit, we can now add some more code to smooth out the movement of the camera as it follows, stop play, open the cam file script again, make a new line of variable section, we'll type in public float, we'll call this variable smooth time, set this equal to 0.3f, hit enter, we'll add another variable, this will be a private variable, it'll be a vector 3, we'll name this velocity, and we'll zero this out initially. The smooth time variable we made will allow adjusting the camera drift in the editor, velocity is a vector 3 value we will need for our smooth damp function, and a fixed update method, click at the first curly bracket, hit enter, to make a line, and type vector 3 target, this is a variable we'll call in target position, we'll set that equal to target.position plus offset, this creates a placeholder variable named target position that we can use instead of typing out the whole expression every time, delete all the code after the equal sign after the transform position, and type vector 3 dot smooth, and that gives us a smooth damp function, we need parentheses, inside of this we're going to type in transform dot position, comma, target position or variable, comma, reference, it's going to reference our velocity variable, comma, and smooth time. The smooth damp function smoothly interpolates the value towards the target over time, transform dot position is the current position value of the camera, in this case, the target position is the target plus offset, the current velocity is referenced to the velocity variable that we initially set to zero, this variable gets updated by the smooth damp command over time, smooth time is the time it takes to reach the target value during the interpolation, save the code minimize visual studio, play the level, change your direction quickly, and the camera smoothly adjusts to follow, stop play, save the scene, in the next lesson we're going to learn how to add interactive traps in Unity, thanks for watching.