Cinemachine Follow Camera

00:00:01:05 - 00:00:24:15

Peter

In this section, we are going to create a camera set up that follows our player around the map. We are also going to limit what the player can see to the areas of the mob that we have prepared using our talent op ed. And we are also going to apply the pixel perfect camera to make sure that our pixel art looks great in our in-game cinema.


00:00:24:16 - 00:00:49:23

Peter

Shooting the camera is an additional package in unity that we can use to help us to create a camera that follows our player in our project. First thing to do is to check if we have this package installed, so we need to go to the top menu window Open Package Manager In the top left corner of this new tab, we need to select Unity Registry and underwrite.


00:00:49:23 - 00:01:14:22

Peter

We need to type in the search box, see the machine. You will find this in our mission package. We are going to need to install it, so I'm going to click it and it will take a bid to install this package. When it is done, we can go back to our A scene view and we will need to select our hierarchy and the plus button because we are going to add a the machine, a camera entry will be available at the bottom.


00:01:14:28 - 00:01:38:17

Peter

There is this in the machine, a category and at the bottom of this category you are going to find the 2D camera. So let's say like this one, and we are going to see a virtual camera object appearing in our hierarchy. Let's go it. Follow camera. Okay. Now, in our game view, you will see that something has indeed changed and our camera is not showing.


00:01:38:17 - 00:01:59:11

Peter

What did you do? So in addition to that, if you go back to the hierarchy and the general section and open the the main camera, select it, you're going to find it at the bottom of this. There is a new component which is collecting the instructions sent by this information In camera are a follow camera object to the main camera.


00:01:59:20 - 00:02:17:18

Peter

If for some reason you see in your project that you are seeing a machine, the camera is not working. Chances are that you might have been missing this interaction. Brain object. This is automatically added when we added to the machine camera. Let's select our full of camera again, and in this picture we can see that we have a lot of options.


00:02:17:25 - 00:02:42:13

Peter

One thing that I want to set for now is the lens also size. We are going to set it to be five and in the game view, you should see that it looks much better with this size of the orthographic lens. Let's go back to our hierarchy because right now in the inspector, when we see the cinema in virtual camera component, we have those follow and look add fields that has currently no transform.


00:02:42:26 - 00:03:06:21

Peter

So we are going to assign to this the layer object. We have to go to the hierarchy, to the agents category, and let's drag the player agent to those two fields is the following field and look at field of our cinema showing a camera what this will make it. It will focus our camera on the player itself. This is basically it for our setup so we can press play.


00:03:06:21 - 00:03:26:26

Peter

Okay. And in the game view, you should see that the camera is now following our player, although we still have this issue where we can see the outside of our farm up and still we can work through the fans so we have no collisions. But let's handle one thing at a time. We can see that, we can look around and the camera is following our player.


00:03:27:02 - 00:03:47:13

Peter

So this is working great. Let's stop our game. Well, in the play mode, if you work in the game view, you should see that we are not following our camera in the scene view. One tip that if you have something to debug when the player is moving and you want to see some gizmos that you can see in the scene view because your player objects.


00:03:47:13 - 00:04:10:05

Peter

So this is the player agent in the hierarchy and you can press shift F and the camera in the scene view. Now we'll be following our player. So if I move in the game view, you should see that in the scene view as well following our player, which will help you to debug any issues that you have in your game when you need to also see some other gizmos that you only go see in the scene view.


00:04:10:11 - 00:04:39:24

Peter

Okay, To keep our project organized, let's go back to our hierarchy and when we stop the game, let's press this plus icon and create an empty game object. And we are going to call this system's you are going to place the follow camera inside the system folder, make sure that the systems folder transform is reset. They follow camera, Transform will have some values because it is moving together with our player object.


00:04:40:07 - 00:05:03:27

Peter

Let's also drag the the follow camera into our prefabs folder. I'm going to drag it now. One problem with making the cinema action camera into a prefab is that we have no follow or look at target selected because it is separate from our prefab, but we are going to be able to reuse it now with our other scenes.


00:05:04:06 - 00:05:14:20

Peter

So it is always worth making a prefab out of your camera. We are also going to create a prefab out of our main camera later on. For now, make sure that you save your scene.



Complete and Continue