Hello guys.
Welcome to the video.
In this one I want to show you how to make camera transitions.
It's going to work in a very similar way to what we have in Celeste.
And to show you that we actually need a bigger level, let's go ahead and make a folder inside of a
prefab folder.
We're going to need folder for camera.
I'm going to do camera.
Then I'm going to take these two and drag them into the camera's folder like that.
Now let's go to asset scene.
I'm going to take level three and I'm going to duplicate it.
Let's make it as level four.
Before I forget let me go to build profiles and drag it here.
I'm sorry.
Sin list and drag it here.
Nice.
Now we're going to close this and we're going to go to level four.
Save it.
So over here I need to make a level that would have two screens.
So for example one screen over here and one screen of the level here I'm going to do it in a time lapse.
Nothing new.
Just a couple of platforms and a couple of places to jump.
All right.
Now, look, I've created part of the level I think I like the first half.
Now I need to know approximate size of the second part of the level.
So I'm going to go to cameras.
I'm going to drag this level camera over here.
And also you need to drag camera manager and keep it here.
I'm going to delete the main camera because we have camera manager now and level camera is over here.
And I'm going to duplicate the level camera because we're going to need to do transition from one camera
to another.
So let's duplicate it and let's move it.
Um.
To the right over here like that.
So now we have the area in which we supposed to have the level.
This is the area.
All right, I think I like it.
Now let me think of some obstacles here.
Here.
As you can see, I like to do wall jumps, so that's why I'm doing it that way.
Uh, let me see the waypoints.
Yeah.
Looks good to me.
Let's move.
Checkpoint over here.
And yes, this should be good.
Now we need to take the finish point, place it here and some fruits should be here.
All right, so this is good.
I like what I have here.
Now, how do we make transition between cameras?
Actually that is super, super super simple.
Let me just take these fruits and put them into a parent because I don't like the mess in the hierarchy.
Fruits.
Take these, drag them into fruits.
All right.
Now if you want you can disable all fruits together.
Um, back to the camera.
On each camera we have this cinemachine limits which have trigger Collider.
And on enter to this collider, we can enable the camera and make it follow the player.
And that's what we're going to do.
We have a level camera object.
We just need a script for this.
And the script let's do.
Uh, script.
Come on, make a script, boy.
Level camera.
And we also need level camera trigger.
C sharp script level camera trigger.
Okay, now let's take the limits over here.
Pull the trigger on and let's take the level camera and put the level camera on.
Now for the level camera we need to get access to this component over here.
Right.
That's what we need to do.
And from this script over here, when player enters the trigger, we need to call method from a main
level camera script and ask it to follow the player.
So let's go to level camera first.
We're going to make private cinemachine.
The new machine.
Wait, how do we do that?
Cinemachine virtual camera.
All right.
Cinemachine.
Okay.
We can see it was changed.
We just need to use Cinemachine camera instead.
Okay, let's try that.
Okay, good.
Then in the week we're going to do Cinemachine equals to get component of Cinemachine camera.
But in.
Children.
Okay, good.
Now first I want to be sure it is working.
So I'm just going to go to unity.
Gonna enable debug mode and I'm going to go to play mode.
It did work.
Okay.
We have reference to this one.
Very nice.
Now let's go back to scripts.
And we're going to need a method that would make, uh the camera follow the transform.
So I'm going to do public void.
Cameras are maybe set new target.
We're going to pass transform new target.
And then inside we're going to do Cinemachine follow equals to new target.
Simple as that I like it I like it a lot.
Now let's go to the cinema scene.
I mean level camera trigger over here.
We want to get component of level camera level camera.
Then we want to do on trigger enter to De same as we did with any other things.
I'm just going to use component to detect the player.
So let me go to the image trigger I'm just going to copy this over here.
Go back paste it in.
And instead of damaging and knockback I'm going to do level camera new set new target player dot transform.
Just like that.
Also would be nice to disable the camera I think just in case.
So let's go to level camera over here and let's do.
Public void.
Enable camera, we're going to do bool enable.
That's what we're going to pass.
And inside we're going to do Cinemachine GameObject set active to enable.
All right.
We're just going to need to use it on trigger over here.
When we enter the trigger we're going to do.
Level camera enable camera equals to true because we want to enable the camera and then set follow and
on trigger exit to D we're going to do the same thing man.
Now I think I should use tags honestly.
Why not just just make sure you don't make a mistake with the tag and it will be fine.
Well both ways are working fine, so it's okay.
So if player not equals to null, then we're gonna.
And disable the camera when we exit the trigger.
And probably that's just it.
We don't need to do anything else.
Okay.
Very good.
Now let's save this.
Let's go back to unity and we're going to take level camera.
We're going to go to normal mode and we're going to apply overrides.
Nice.
Now this will be applied to any other camera you have in the game.
And we have two.
And by default, actually, I think we should disable the camera.
So let's go to.
Let's just disable the camera like that.
Yeah.
Good.
In case you forget to disable the camera, we can go over here.
And in the wake, we can do enable camera.
Uh, pulse is going to disable the camera on the awake, but player will enter the trigger and it will
enable the camera where your player is.
Now, let me try that.
I'm going to place my player over here on the edge.
And I'm going to try to walk to another room.
So I'm standing there.
Wait.
What is it?
Couldn't get it because I did disable the object.
Okay, my bad object is disabled.
We're not getting component.
Let's type true over here.
Let's save it and let's go back.
Okay now.
It's fine.
Now it's not.
What is it?
Uh, we need to be sure it's working.
Object reference not set is an instance of an object.
Why not?
Oh, I am so sorry.
I forgot to get the component awake.
Level camera equals to get component in parent.
Off level camera.
Okay, nice.
Let's save this and let's go back to unity again.
Okay, no more errors.
We can see.
Camera is fine.
We can see entire level.
I'm just going to go ahead and try to switch the level and boom we are on the new camera.
Very cool.
There is one issue though.
It was kind of fast and although I kind of like it, honestly, I kinda like how it works, but it's
better to do some sort of blend between the cameras.
And it was supposed to work automatically, but I don't see the blend.
Let me try to fix it.
All right.
All right, I see what the problem is.
Um.
Over here.
I have Collider here and second limit is over here.
So we have like lots of space between them.
And I think that's not really good.
So let's take the limits over here and maybe let's increase them.
Like that.
Now let me try again.
Yeah, now it is smooth, I like it.
So what you can see here is a blend transition between cameras and.
And you can adjust it.
Sorry, I was busy killing enemy.
You can adjust it over here by using default blend.
You just change the default blend or you change the duration of a blend.
For example, you can do 0.5, then it will be faster like that.
Or you can do five seconds.
Then it will be longer like that.
For example, when you want to present a new level, this is a valid option.
I kind of like it.
Although I don't like what is happening there with, uh, uh, walls.
You can see that, right?
Let me see it closer.
I sort of find it was not fine only in the small window, but like that, I think it's okay.
Uh, let me try shorter blend.
And you can experiment with these, try on different things.
Maybe.
Let's do cut.
Then it will be like that.
Let's do hard in.
Let's do hard out.
Yeah.
So again, personal preference.
You could do custom blends or you could do linear.
It's always up to your decision.
Don't worry about that glitch.
It is fine when you make a full screen.
So we have a nice camera.
Also, something about this you can, um, set up camera differently.
For different areas.
What I mean by that, you have full control of the camera.
So you can go to this camera over here and change lens to something like four, for example.
And then when you go to the next room, your camera will not only change the view, but also it will
change the zoom like that.
And you can present a new challenge to the player where he cannot see much.
For example.
Yeah.
Well, that's very good.
I like it, I'm going to change it back to ten.
That's how I like it.
And this is how you set up transition between cameras.
Now we have bigger level with different cameras.
And the last thing we need to do before I forgot we need to go to other levels like scene like level
two.
Let me save changes.
And over here we need to add cameras from prefab.
So camera.
Let's take these two.
Drag them here.
Let's delete main camera.
And these two can be over here.
And you just need to take the level camera and adjust it to the limits you have here.
So I think I want player to see.
Maybe this much.
Okay, now let's go to asset scene level three.
Save going to go to prefab.
Take the cameras.
Drag them here.
Delete main camera and for the level camera, just place the limits as you like.
Okay, I think I like it.
I'll see you in the next video.
Then let's save this and let's go.