Let's make the camera follow.
So if I go ahead and then hit this play button in the top in order to play our game, you will see my
camera is not moving at all, even though we are moving our player GameObject left and right.
Let me show you first.
So let let's for a moment, let's, uh, wait a moment and we can see.
As you can notice, the camera is not following, uh, our player at all.
So we need to follow our player to do that for we will install Cinemachine Cinemachine camera in order
to follow our player GameObject.
So let's get out of play mode.
Uh, to install Cinemachine, go to window.
In the top you can see in the top bar window.
Then move over to this package manager and in the left side you will see in project.
In the left side you will see Unity Registry.
Basically select the unity registry and over here you will see.
So scroll down to the bottom and find over here cinemachine.
And as you can notice right over I have.
And if you not able to find it make sure you are in unity registry basically in the left.
Choose that.
Then search over here by typing cinemachine and it's gonna pop up and you will see an import button.
Sorry, you will see an install button.
So just click there and then Cinemachine just gonna import in your project.
And once you are done and you are good to go.
As you can notice, I already imported my cinemachine camera in my project.
So let's cut this tab by now and let's create the camera.
To create the camera, go over to hierarchy, right click or hit this plus icon.
Then go over to Cinemachine.
In the bottom you can see.
Then target is camera and then click on this 2D camera.
And now as soon as we added our Cinemachine camera we can see that.
And if we select our main camera, we can see a.
Basically, if I select my main camera, go over to Inspector.
In the bottom you can see Cinemachine brain just added up to our main camera.
As soon as we created this Cinemachine camera, why basically this Cinemachine brain component just
gonna give instruction to our main camera, basically Cinemachine camera, just gonna give instruction
to this main camera.
So that's why this cinemachine brain just added up.
So let's suppose we just want to move to the left direction.
So this cinemachine camera just gonna give instruction instruction to this main camera in order to move
this main camera to the left side.
So that's why this cinemachine brain just added up right away.
Once we created this cinemachine camera, it's gonna give instruction to our main camera.
But if we just go ahead and then play our game, you will still able to notice our play.
And basically main camera.
Not gonna follow our player game object at all.
Why?
Basically, we need to make the tracking target.
So if I just move left and right.
As you can notice, main camera is not following at all.
For that, we will get out of play mode for it.
We need to select our Cinemachine camera in the hierarchy.
Then go over to Inspector, then Cinemachine camera component.
And over here we can see tracking target slot and it says None transform.
Basically we need to drag the GameObject.
Which GameObject we just really want our main camera to follow.
So in our case we're gonna follow our player GameObject.
So that's why we will select our player Game object from hierarchy and drag it over to that tracking
target slot.
And as soon as we drag it now our main camera just gets his position to our player a game object.
And if we just go ahead and then click on this play button in the top, you will see.
By now, the camera is just gonna follow our player wherever player goes to the left or right direction.
Even we jumping.
So if I just play my game, if we try to move left and right.
As you can notice, main camera is now following.
And if we jump in the way we can see indeed our main camera is following our player game object in the
y axis as well.
Let's suppose you want some area you don't want to move or don't want to move your camera.
But if you surpass this position and you want your main camera to follow, then you can just do that
for it.
What you have to do, you need to move over to Inspector.
Firstly, select your cinemachine camera in the hierarchy, then go over to Inspector, then Cinemachine
camera component, then Cinemachine position component.
In the bottom you can see.
So just go there and then click on this date zone and click on this date zone.
And as soon as we check we can see an area just just became in our game view.
We can notice that.
So this will be the area that if we just move around in in this area, in this area then main camera
not gonna follow at all.
But if we surpass this area then our main camera will start following our player game object.
Let me show you.
So as you can notice that if we try to move left and right, we are not able to notice our main camera
to follow.
But once we surpass this area, basically this dead zone we can see the main camera is not is basically
following our player.
So this is the dead zone and you can just play around with this number.
So I'm gonna make a little bit small.
I want a small area.
And if I just surpass that area then I want my camera to follow this player game object right after
this player game object.
So to do that, we will go over to Cinemachine position component component right over here.
Firstly, select your Cinemachine camera in the hierarchy.
Then go over to Inspector.
In the bottom you can see that component which is uh which says Cinemachine position component.
And we can right click on it.
And if we click on this properties it's going to pop up with an tab.
As you can notice right over here.
And you can just play around with this value.
And let's say I want a little bit small this area which is the death zone.
So I'm going to choose something like point instead of point two.
And we can see the area is now little bit.
But so in this area we can just move left and right.
And when camera is not following at all.
But once we surpass this area, camera just started following our player in the x axis basically horizontally,
as you can notice.
And if you want to do with in the Y as well, you can just increase the value in the Y.
I'm not gonna do a doo doo at all in the y axis, so I can just set it to zero.
So it's not going to do at all.
And we can play around with the is basically this is a screen position.
If we set it to zero let's suppose you want to increase this value.
As you can see.
Are we gonna be here.
You can just play around with this.
I'm gonna set it to zero.
And let's suppose you just want to move your camera a little bit up direction or vertically.
Then you can increase this y value.
And we can see as soon as we increasing.
Sorry.
Not increasing basically decreasing.
We can see the main camera in the y axis is getting a little bit up.
And you can just play around with that number.
And since I one sorry increasing or decreasing I don't know.
Sorry.
We need to play around with this value.
So we gonna set back to zero.
So just play around with this, and you're gonna get all of the things you can make the target offset.
We can see right over here.
We can do it like this, and we can play around with the Y as well.
And I'm going to set back to zero.
So just play around with this number and you're gonna get all of these things.
And make sure you just right click on that.
Right click on Cinemachine a Cinemachine position composer component.
Sorry Cinemachine Position Composer component.
Right click on it and then copy component.
And because we're doing inside a play mode, so it's not gonna save at all.
So once we get outside of play mode.
So that's why we need to paste those values.
Or we need to remember this since I don't want to remember.
So that's why I'm gonna right click on that component which is Cinemachine position composer component.
Right.
Let's right click on it and then click on this copy component.
So all of the properties we just copied.
And we can just cut this tab.
or you can simply move over to your inspector, then go over to bottom Cinemachine.
Cinemachine position Composer component.
Right click on it and then copy.
Click on this copy component.
So it's going to copy all of the component.
And if we get out of play mode we just getting back our value to default.
So what we can do by now we can just right click on that component and then right click on that component.
And then we can just click on this paste component values.
And as soon as we paste we can see the dead zone that zone in the X or horizontally which are which
we set inside play mode point one.
And now it gets back to point one.
Once we just paste our component values.
So you can just play around with this and you're gonna get all of the things.
Let's suppose you just want to just want your main camera to zoom in.
Then what you need to do, you need to go over to this cinemachine camera component.
And then you need to move over to this lens and you can just play around with this value.
So if I increase orthographic size.
So make sure you select your cinemachine camera first.
Then go over to Inspector Cinemachine camera component and then move over to this lens section.
And if you just increase that value something like ten, we can see the camera just zooming out.
And let's suppose you want to zoom in.
Then you can just decrease this lens value to something like five.
And if we set it to five it just zoomed in.
So I'm going to set it to seven something like that amount like that.
And if I select my different game object in the hierarchy now we can see that it's gone.
Basically the outlines the lines is gone.
Because as soon as we choose our cinemachine we can see this line, as you can notice right over here.
But if we select different game object in the hierarchy, we can see those lines just a fade just goes
out.
And if we just go ahead and then click on this play button in the top to play our game, we will see
our main camera.
Just gonna follow our player game object in the direction the player is going, and play around with
those values like the death zone in the X and Y, and you're gonna get.
As you can see, this is our death zone.
But once we surpass this dead zone, the camera started following our player in the Y as well as in
the X axis.
And we can play around with the offset if you want your main camera a little bit up direction in the
Y, then you can just get out of play mode, then select your Cinemachine camera, then go over to Inspector,
then Cinemachine Position Composer component in the bottom.
Then go over to composition composition right over here and increase the value or decrease the value
in the Y.
And you're gonna get that.
So basically that is the thing.
So I'm going to set it to something like point one, point one, something like that.
Or we can just make this value small.
So it's going to be in the up direction, I guess we can play around and we're going to get that.
So you can just play around like this.
You can just increase or decrease.
It's basically after you if you just want your main camera in the up a little bit in the Y direction
or in the up direction a little bit.
So basically that is the thing.
So I hope you get the idea that how you can install your cinemachine, uh cinemachine camera and how
you can import in your project and play around with these values and you're gonna get that.
And also we need to drag our backgrounds, we need to make parallax effect and all of those things.
Also, we need to make the camera shake effect as well.
So we need to do those things.
And we're going to do it in the next, uh, in the later lectures.
So I hope you get the idea that how you can do this.