Monster shadow

VIDEO

2D Camera in Unity + Confining to bounds [Cinemachine]

Description:
Create the perfect 2D camera in Unity. Cinemachine gives you AAA quality camera controls within seconds. Creating your own camera script, although a viable option, can be very time-consuming and unless your camera controls require something completely unique, Cinemachine will give you what you need. =========
ADD A COMMENT

Song Editer
my character become slow when he is inside the polygon collider 2d. can you help?
Krupal Parekh_42
Hi sir , can u help me plz, I make a 2d platformer game I try to follow my player to cinemachine . In that I some add extensions in that I add cinemachine confiner . In that bounding shape 2D I add a polygon collider 2d form that my player fall down , I can't understand why that happened can u help me to solve that .
ReiNStern
Thank you, is actually easy to do
Tarodev
Cinemachine is a fantastic library
Sparty Developer
Thank you for this tutorial, straight to the point and just learned some new stuff about cinemachine :)
Hossein
hi. thx for your tutorial. i have a complex scene with lots of edges. camera with confiner is not working smoothly. it will move like it is teleporting!
Lora
Hello! Please! Tell me why the zoom does not work in cinemachine and does it work without cinemachine? Only Pan script works. Zoom script doesn't work. Why is that!?
Matt P
THANK YOU!
Yiğit Emir
thx bro
Anon N
Great video. Exactly what i was looking for. Thank you very much!
Nuno Torradas
THANKS!
Andy M
thank you so much, I ve been looking everywhere for this
Sloogadude
Great - straight to the point
Satyajeet Mohanta
Do I use these scripts in Tile Map Background..???
Tarodev
I'm not sure what you mean? If you're talking about the confiner, you just need a collider to use which can be anywhere. Make sure it's a trigger so it doesn't smash everything in your scene.
Programming Nusantara
Thanks a lot 👍
S&I Games
Thank you very much!!! I was looking for this!
Snpr Skllr
lol never thought cm had a looking ahead function i was using my custom camera just cause that reason and it was very jittery so thanks for telling me that 😁
Tarodev
Before throwing your custom camera in the trash, try playing with the camera follow targets rigidbody interpolate setting. Swap it from interpolate to extrapolate, or visa versa, and see if the camera smooths out.
Snpr Skllr
also got a new subscriber
Ridlr
The damping option for the confiner doesn't seem to really work very well. I thought it would slow down when approaching the edges but instead it just goes past them and then comes back. Is there any way around this?
KL Chan
Hi! May I ask if "level" is a empty item or it is a specific type of object? I set up a confiner as one of the objects but the camera and character still slip out of the game play area. Thanks!
Tarodev
If the CHARACTER is slipping out then that's unrelated to the camera. If you want to confine your character to an area you'll need to setup the boundary colliders in the level. These colliders will not have "Is Trigger" set, similar to your ground. Hopefully I understood your problem correctly.
KL Chan
thank you so much for uploading this 4-min clip, I have been looking for a solution for three hours!!
KL Chan
Ahh I found the reason. "Is trigger" under Polygon collider 2D should be checked. Once again thanks for making this video!
KL Chan
@Tarodev Thanks! After the confiner has been set up, the player was automatically kicked out from the main screen as I pushed the "play" button. However it didn't happen in another game which the virtual camera and confiner had been set up the same way. May I ask what other aspects should I look at? Thanks.
Tarodev
Good luck with your camera setup :)
NrMines
Cheers
SEE ALL COMMENTS


Transcript:

in this video i'll show you how to set up a quick 2d camera
with a few tips and tricks as well as confining your viewport to the relevant
play area okay so first thing you need to do is
window package manager and then just ensure that cinemachine
has been installed all right next go to the cinemachine tab
up here and click create 2d camera what this will do is it will create a
what's called a virtual camera on your scene and
effectively what this does is it's it replaces your camera transform
kind of so if you'll see here i've got my virtual camera selected
when i move it around my actual camera itself is pinned to it
okay so all we need to do to get this working and following
our player is simply drag on our player into
the cinemachine virtual camera follow slot
now if we press play you'll see it's already giving us pretty
pretty nice desirable results so there's a few things we can do with this
for example over here on the x-stamping and wide dampening
let's change that to five and if we go back in game
we'll see it adds a bit more of a floaty feel to it kind of looks a little bit
cinematic next i'm sure you noticed these red
borders here so that's called the dead zone and it will
only show if you've got your virtual camera selected
but the way that works is if we just go this way you'll see that the character
will never be allowed to leave your confines
like that another cool feature of cinemachine is the look ahead time
so if we just go put this to about four add a bit of smoothing to it now you'll
see when i run you'll see the camera is kind of like
looking ahead of where we're actually going
so obviously if you've got like a fast-paced game and you're running to
the right you you want the player to be able to actually see what's coming so
cinemachine can easily handle that for you all right so
what if you don't want to show this much of the level all at once
so what we can do is let's just reduce the size of our player here a little bit
and let's zoom the camera in just a tad just like that
okay so now now we don't have the full level in view
so that's all right but what about all of this blank space here that's not
really helping anyone what we can do is we can confine the
camera to a certain area okay so this is incredibly handy so with
your virtual camera selected scroll down the bottom and you'll see
this extensions part here if you click that and you add a confiner
in so what this is going to do is it's going to confine
where the camera can actually travel alright so to give the
confiner plug-in what it needs i'm just going to create a child of this level
and call it confiner and then i'm going to add a polygon
slider 2d to it and then click the edit collider button
and then i'm just going to drag this around my level roughly to
where i want the camera to be able to see to
with a little bit of padding there and i'm going to make it a trigger just so
it's not colliding with everything in a scene
and then on my virtual camera just slide in the confiner
okay so let's give that a go i'll full screen it
add a little bit of floatiness to the camera let's try it out
and yeah there we go so it's keeping the camera um
on the player and it's following it but it's not
allowed to go beyond the bounding box and show all that useless stuff it's
keeping more of the actual relevant parts of the screen of the
screen in view so i hope that helped uh if it did
leave a like subscribe and i'll see you next time for another tutorial
you