@Terry Field, for some reason TH-cam wont let me reply to your comment. I would make sure you added the Player tag to your player and that it was spelled exactly the same way in your if statement and actual tag.
Everything work good exept now it messed up my player controller i can spam the jump button and fly forever do u think u might know what the issue is ?
I know this is an old tutorial, but it is freakin' brilliant. You have shown me in 8 mins what I've been trying to get this blasted camera for ages to do :) Thank you soo much
My camera is following in all directions until I exit the room collider, but I need to stop horizontal movement before the camera shows the next room. Any ideas? EDIT: It seems like the option "Confine Screen Edges" is gone in newer versions of cineMachine. Maybe that's the problem? SOLUTION: The option "Confine Screen Edges" is only available if the main camera is set to orthographic!
Thanks for this tutorial man! I couldn't even google this thing properly, just couldn't find the right words. Anyway, I'm going to remember Cinemachine from now on
For anyone having troubles with the Cinemachine camera not detecting the player at all, please remember to give your player a 2D box collider and a 2D rigid body :) Spent way too long trying to figure out why the camera was not working to for me to facepalm upon figuring this out.
Thanks for the great video, got me rolling on how to implement. A maybe better way for numerous rooms is to create an OnTriggerEnter script for each area collider component and then reference the Cinemachine 2D Confiner to switch the collider being used when entering the room, in that way you would only need one cinemachine virtual camera in the scene and just the collider it focuses on is changing.
@@unloadedmaster1176 Hey! I used an ontrigger event and attach it to any of the polygon colliders around the room, I put a tag 'Confiner' on all of those gameobjects. You can reference the cinemachine confiner current collider and change it from code. The one thing you'll have to play with if you do this is maybe pushing the player fully into the room, because if you slowly go in the collider may not fully trigger and your player will disappear into the other collider. I do end up using an ontriggerstay2d and make sure player is fully in collider but this below should get you started, I put it on the player collider gameobject. Reference the Camera, in my case I just used a serialized field. Then create a confiner reference. [SerializeField] CinemachineVirtualCamera _virtualCamera; CinemachineConfiner2D _confiner; private void Awake() {
is there a way to do this with only one virtual camera ? i feel like creating bunch of cameras is not the best solution :/ like changing the bounds once the player enters another one
My camera keeps snapping instead of smoothly transitioning. Do you know the reason why? Edit : I fixed it. My room triggers were too far apart. Which is why the cameras were snapping.
@@dark_j_gamer5285 This was the exact same problem for me, thanks a ton man. I had this problem a couple of months ago and i had to quit a whole project because of it. Thank you
I'm sure you've figured it out by now but most likely what you wanna do is create a static script that handles that stuff. Have it run a destroy enemies function or something that is called whenever OnTriggerExit2D is called
Just an update of this video: there is another extension called "Cinemachine Confiner 2D" compared to this video. This is NOT this component used in this tutorial: the far better one is still "Cinemachine Confiner" (it might fit with the first one with some work, but small colliders will make it buggy)
Hey i folowed the tutorial but the Confine Mode does not work for the Y axis , whenever i go up too far my camera just folow and go over the confine 2D. But it works well for X axis
Thanks for the tutorial, this gave me some ideas. I removed the confiner (as it's not really necessary for me, the script don't need the confiner) and I also added a script to make my box collider 2d match the camera frustrum. This idea has a lot of potential :D
it worked for me as in the video, but when the player dies and restarts the area, the camera stays in room 2 (even though I didn't get there before I died) can someone help me?
omg, thanks for the tutorial. It was so easy to understand and I'm going to use it for my school project but one thing. The scene becomes a little wobbly or idk at a certain point I have reached the conclusion that it moves when passing the blue lines. I'm still going to search on my own but your help is apreciated!
If you don't want to have to drag in the CM vcam every time, just name all of your vcams the same thing (eg: "CM vcam1") and then in your script add this: void Start () { virtualCam = transform.Find("CM vcam1").gameObject; } It will automatically find the child object so you don't have to drag it in every time.
Perfect! Exactly what I needed to know, explained better than most Unity tutorials do. Thanks! Strange thing though, the virtual cameras do exactly what I want, but when they're active my player's jump controls completely change -- aircontrol is suddenly allowed, none of my floor/wall/ceiling checks happen. I don't get why the cameras would affect that at all...
seemslike i run into a problem, the transition wouldnt happen, both virtual cameras is disabled, and didnt SetActive, i dont know whats wrong, tho anything else is great, and no error message pop up
I have a problem. Now when i press play, it always starts with second vcam where is nothing. I have to drag gameobject(player) to second room and then run to first one. It starts from second vcam, idk why.
Maybe make sure both of your cameras are disabled in the hierarchy and double check your code. I would need more info if you are still having problems.
BenBonk pretty interesting. Yesterday was doing new version of unity update and after update this camera transition didnt work. Today after Pc restart is working fine :D
Reeeally useful tutorial, it works great. One question! How can I have my Player respawn at the beginning of the last virtual camera they entered? Like in Celeste you don't respawn at the beginning of the level, but at the last area you entered. Does anyone have any ideas?
for now i just added a prefab called "respawnpoint" wherever the player switches rooms. The player has a private Transform lastCheckpoint and when dying, youll respawn there.
I know you might not know the answer but I have been using the corgi engine asset and for some reason this doesn't work for me I'm assuming it's the asset but I just have no Idea what it could be from the asset causing this. Everything seems to work perfectly until I turn off both my Cameras and it dosen't turn them back on upon hitting play, I have double checked my code and it's exactly the same as yours.
I'm having an issue. I'm using a player with multiple colliders and to crouch I disable their top collider, but this calls the "OnTriggerExit2D" function as technically the collider that was disabled has left the polygon collider. This is causing the camera to disable while the player is still in-frame and then re-enabling it after I stop crouching, which causes a huge visible tug of the camera back to the polygon.
Hello, first of all amazing video! I am currently trying to programm a small Vine Swinging Game. The idea is pretty similar concerning the camera movement, since I generate my level sequentially. My only problem is now, that I dont know how to allow the camera so just "add" the new confinement zone to the already allowed one. Like I got 4 prefabs for levelparts, which are randomly linked to each other. And the camera should be able to go to the right, but not up/down or to the left. Is this somewhat possible? Until now I didnt really find a good manual/tutorial that tackles something with sequential generation =(
ayo man I know this was 2 years ago but I somehow found out how to fix that shit so I'm here to help anyway: what I found out is that when this was happening to me, it would always first go to the right (even tho i went left) and then it started working as supposed to. so I found out its a simple fix. just add: private void Start() { virtualCam.SetActive(false); } :)
My bad dude, sorry to wake you up from your 2 year slumber,but my fix is something different than what you needed help with. My problem was about being able to go right but when i went left, camera still went right, so if you'll have problem with that, THEN this can help you. Sorry dude
This is amazing, thanks! I wanted to ask you if there's a way, after passing from Room1 to Room2, to not allow the character to go back to Room1. Thank you in advance!
I have a problem, I disabled both camera in hierarchy but when the game starts it doesn't enable the camera.... Can you help me? I made sure that the tag was player and both of the camera are disabled in the hiearchy. Edit: This is my script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class RoomManager : MonoBehaviour { public GameObject virtualCamera;
hello i tried using this video to make a platformer type game. but when i try to put the sctipt in the rooms it says "Can't add script component'room' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." pls help
@@BenBonk now i have a new problem. ok i kinda broke my game so that i had to start on a new. but now i can't get the camera to change between the to rooms. i can see that it enables in room 2 when i go there. but the camera doesn't change. sorry for all the questions i am asking.
With the newer versions, Cinemachine no longer appears in the main menu. You’ll find it in the GameObject menu, or if you right-click on the hierarchy.
the script for people that are lazy: using System.Collections; using System.Collections.Generic; using UnityEngine; public class cam : MonoBehaviour { public GameObject virtualCamera;
Hi, I am a Kazakh who speaks Russian, so don’t be afraid of crooked English. So I have a problem. When I jump and move between rooms, the camera jumps, but not very noticeably. But for me it hurts my eyes, how can I fix it?
@@BenBonk Checked, now works. Thank you so much. Now I have a new problem, it is more picky, but still. When I go from left to right of the camera and vice versa, it moves a few centimeters. This is the default camera Unity. How to fix it?
Cool! But how to do this with Corgi Engine? Everything is done according to the instructions, but something does not work out. Room colliders do not respond to the character.
ive used corgi engine before,, have a look at the documentation for "cinemachine zones", its exactly what this video does but within the corgi engine framework
Hello. Im having an issue with the polygon colliders, I believe it forces my player into crouch mode constantly, as the jump height isnt affected and the would-be regural speed is matching my crouch speed. I used movement from this video: th-cam.com/video/dwcT-Dch0bA/w-d-xo.html&ab_channel=Brackeys Please if someone found a fix for this, lemme know, Im newbie in gamedev
@Terry Field, for some reason TH-cam wont let me reply to your comment. I would make sure you added the Player tag to your player and that it was spelled exactly the same way in your if statement and actual tag.
Everything work good exept now it messed up my player controller i can spam the jump button and fly forever do u think u might know what the issue is ?
I'm learning 2D Unity dev and camera was the first thing I encountered
this camera effect is pretty epic (considering me as a celeste fan)
I've spent 3 hours trying to figure out exactly this, thank you very much for a great tutorial!
I know this is an old tutorial, but it is freakin' brilliant. You have shown me in 8 mins what I've been trying to get this blasted camera for ages to do :)
Thank you soo much
Thanks :)
This is actual one of the moste useful toutorials in the whole Internet. This was a good idea to make, and really good made too.(: Hope u make good
My camera is following in all directions until I exit the room collider, but I need to stop horizontal movement before the camera shows the next room. Any ideas?
EDIT: It seems like the option "Confine Screen Edges" is gone in newer versions of cineMachine. Maybe that's the problem?
SOLUTION: The option "Confine Screen Edges" is only available if the main camera is set to orthographic!
Really good tutorial, exactly what I was looking for! Thanks!
thx BenBonk - I struggled to find good info on how to implement this until i found this video; concise, simple, accurate. very much appreciated.
Thanks for this tutorial man! I couldn't even google this thing properly, just couldn't find the right words. Anyway, I'm going to remember Cinemachine from now on
For anyone having troubles with the Cinemachine camera not detecting the player at all, please remember to give your player a 2D box collider and a 2D rigid body :) Spent way too long trying to figure out why the camera was not working to for me to facepalm upon figuring this out.
Huge 👍 finally someone did a tutorial on this
Extremely useful and works perfectly. Thank you very much!
Cool video! Easy and to the point, thanks.
thank you so much this is perfect, makes it so much easier for level design
Thanks for the great video, got me rolling on how to implement. A maybe better way for numerous rooms is to create an OnTriggerEnter script for each area collider component and then reference the Cinemachine 2D Confiner to switch the collider being used when entering the room, in that way you would only need one cinemachine virtual camera in the scene and just the collider it focuses on is changing.
This sounds super helpful. Could you elaborate further on this? I am trying to recreate this, but I am currently struggling with it.
@@unloadedmaster1176 Hey! I used an ontrigger event and attach it to any of the polygon colliders around the room, I put a tag 'Confiner' on all of those gameobjects. You can reference the cinemachine confiner current collider and change it from code. The one thing you'll have to play with if you do this is maybe pushing the player fully into the room, because if you slowly go in the collider may not fully trigger and your player will disappear into the other collider. I do end up using an ontriggerstay2d and make sure player is fully in collider but this below should get you started, I put it on the player collider gameobject.
Reference the Camera, in my case I just used a serialized field. Then create a confiner reference.
[SerializeField] CinemachineVirtualCamera _virtualCamera;
CinemachineConfiner2D _confiner;
private void Awake()
{
_confiner = _virtualCamera.GetComponent();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag=="Confiner")
{
_confiner.m_BoundingShape2D = collision.GetComponent();
}
}
is there a way to do this with only one virtual camera ? i feel like creating bunch of cameras is not the best solution :/ like changing the bounds once the player enters another one
this movement is crazy! im using it in my commercial game!
this was super useful and it saved my game
thanks, i'm a beginner and your tutorial helped me. Your tutorial is excellent
just what was i looking for!
My camera keeps snapping instead of smoothly transitioning. Do you know the reason why?
Edit : I fixed it. My room triggers were too far apart. Which is why the cameras were snapping.
Thanks a lot i had the same issue
Best tutorial for camera transitions thanks alot.
There is a weird stuff that when i use a Ground Check it dont work after using the Tutorial and i dont know how to fix it..
if your ground check uses raycasts make susre you set the layer of the rooms to ignore raycast
@@dark_j_gamer5285 This was the exact same problem for me, thanks a ton man. I had this problem a couple of months ago and i had to quit a whole project because of it. Thank you
Mega! Thanks dude, this really helped with a game I'm making.
great tutorial!! is there a way to destroy the enemies when they are not in the active room?
I'm sure you've figured it out by now but most likely what you wanna do is create a static script that handles that stuff. Have it run a destroy enemies function or something that is called whenever OnTriggerExit2D is called
@@cmdrcamper9511 yeah thats exactly what i ended up doing lol its perfect for a metroidvania
Awesome tutorial mate!❤
Thank you very much for this tutorial, works like a charm. Keep up the good work!
For a second, I thought MY one drive was full.
Just an update of this video: there is another extension called "Cinemachine Confiner 2D" compared to this video. This is NOT this component used in this tutorial: the far better one is still "Cinemachine Confiner" (it might fit with the first one with some work, but small colliders will make it buggy)
Hey i folowed the tutorial but the Confine Mode does not work for the Y axis , whenever i go up too far my camera just folow and go over the confine 2D. But it works well for X axis
Ok fixed , my room was too small compared to my camera , room need to be bigger
Some ppl make this so difficult lol thank you for making it simple
Thanks for the tutorial, this gave me some ideas. I removed the confiner (as it's not really necessary for me, the script don't need the confiner) and I also added a script to make my box collider 2d match the camera frustrum. This idea has a lot of potential :D
This video was huge for me, thanks
Np, glad I could help.
This is exactly what I'm looking for, thx
Np
6:27 is there a reason why we need the secondary condition ?
It isn't necessary at all, but it's there so it can't be activated by other triggers.
it worked for me as in the video, but when the player dies and restarts the area, the camera stays in room 2 (even though I didn't get there before I died) can someone help me?
when the player dies im using this code to restart:
private void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
awesome tutorial, thank you
Thanks, this video helped me a lot!
Hi much thanks for the tutorial it works well :) is it possible to have the the player GameObject freeze/slow during the camera transitions?
2 years too late but maybe make it set the move speed to 0, then put it back when you need it
omg, thanks for the tutorial. It was so easy to understand and I'm going to use it for my school project but one thing. The scene becomes a little wobbly or idk at a certain point I have reached the conclusion that it moves when passing the blue lines. I'm still going to search on my own but your help is apreciated!
Clever and useful! Thanks!
Thanks man you really save my life !!
If you don't want to have to drag in the CM vcam every time, just name all of your vcams the same thing (eg: "CM vcam1") and then in your script add this:
void Start ()
{
virtualCam = transform.Find("CM vcam1").gameObject;
}
It will automatically find the child object so you don't have to drag it in every time.
Perfect! Exactly what I needed to know, explained better than most Unity tutorials do. Thanks! Strange thing though, the virtual cameras do exactly what I want, but when they're active my player's jump controls completely change -- aircontrol is suddenly allowed, none of my floor/wall/ceiling checks happen. I don't get why the cameras would affect that at all...
couldn´t it be affected by the polygon colliders? I have similar issue, where it basically forces my player into sneak mode
Excellent i make a 2d game "Anatema" and your tricks saved the management of my ce
Cameras !
Thanks a lot :)
Big man, very helpful
Didn’t ask dawg
can i get a lawyer dog
@@maxmorrison9763 no
Great tutorial thanks you
Thanks, this was very helpful! :)
seemslike i run into a problem, the transition wouldnt happen, both virtual cameras is disabled, and didnt SetActive, i dont know whats wrong, tho anything else is great, and no error message pop up
when hitting "play" both the confiners is not detecting the player, plz help
Is it possible after going into 2nd room that the camera dimensions change?
I have a problem. Now when i press play, it always starts with second vcam where is nothing. I have to drag gameobject(player) to second room and then run to first one. It starts from second vcam, idk why.
Maybe make sure both of your cameras are disabled in the hierarchy and double check your code. I would need more info if you are still having problems.
BenBonk pretty interesting. Yesterday was doing new version of unity update and after update this camera transition didnt work. Today after Pc restart is working fine :D
ProGressive Unity can be like that sometimes!
Reeeally useful tutorial, it works great. One question! How can I have my Player respawn at the beginning of the last virtual camera they entered? Like in Celeste you don't respawn at the beginning of the level, but at the last area you entered. Does anyone have any ideas?
for now i just added a prefab called "respawnpoint" wherever the player switches rooms. The player has a private Transform lastCheckpoint and when dying, youll respawn there.
I know you might not know the answer but I have been using the corgi engine asset and for some reason this doesn't work for me I'm assuming it's the asset but I just have no Idea what it could be from the asset causing this. Everything seems to work perfectly until I turn off both my Cameras and it dosen't turn them back on upon hitting play, I have double checked my code and it's exactly the same as yours.
Thanks! good tutorial!
I'm having an issue. I'm using a player with multiple colliders and to crouch I disable their top collider, but this calls the "OnTriggerExit2D" function as technically the collider that was disabled has left the polygon collider. This is causing the camera to disable while the player is still in-frame and then re-enabling it after I stop crouching, which causes a huge visible tug of the camera back to the polygon.
did you fix it? :( it's happening with me too
Hello, first of all amazing video!
I am currently trying to programm a small Vine Swinging Game. The idea is pretty similar concerning the camera movement, since I generate my level sequentially. My only problem is now, that I dont know how to allow the camera so just "add" the new confinement zone to the already allowed one. Like I got 4 prefabs for levelparts, which are randomly linked to each other. And the camera should be able to go to the right, but not up/down or to the left. Is this somewhat possible? Until now I didnt really find a good manual/tutorial that tackles something with sequential generation =(
ayo man I know this was 2 years ago but I somehow found out how to fix that shit so I'm here to help anyway:
what I found out is that when this was happening to me, it would always first go to the right (even tho i went left) and then it started working as supposed to.
so I found out its a simple fix.
just add:
private void Start()
{
virtualCam.SetActive(false);
}
:)
i guess the vCam needs to start as false for it to work the first time
@@tmsh_ oh wow, ich didnt expect to get an answer. I will try that. I moved on from that game, but thats nice. Thank you very much :D
My bad dude, sorry to wake you up from your 2 year slumber,but my fix is something different than what you needed help with. My problem was about being able to go right but when i went left, camera still went right, so if you'll have problem with that, THEN this can help you. Sorry dude
This is amazing, thanks! I wanted to ask you if there's a way, after passing from Room1 to Room2, to not allow the character to go back to Room1.
Thank you in advance!
lmao place a box collider and after you get into room 2 untick Is Trigger
Idk if you still need this, but you can make a something like a door and if the room 2 tigger is set to active, close the door
thank you, very much
man, thank u so much
amazing thanks
The cam is not going active when clicking play, any possible fixes or reasons?
Yeah I have this problem too
having the same issue
Check if the player object's tag is Player
@@user-eh8tz4vm5f i did change that but i have the same probs
Greate!!!, Tks so Much :DDD
Thank you for this video you win a like
I have a problem, I disabled both camera in hierarchy but when the game starts it doesn't enable the camera....
Can you help me?
I made sure that the tag was player and both of the camera are disabled in the hiearchy.
Edit: This is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoomManager : MonoBehaviour
{
public GameObject virtualCamera;
private void OnTriggerEnter2d(Collider2D other){
if(other.CompareTag("Player") && !other.isTrigger){
virtualCamera.SetActive(true);
}
}
private void OnTriggerExit2D(Collider2D other){
if(other.CompareTag("Player") && !other.isTrigger){
virtualCamera.SetActive(false);
}
}
}
If you need more information can you give me your discord or something so I can send you pictures?
Capitalize the D in ontrigger enter
@@BenBonk Thanks xD, idk how I didn't notic that. Thank you very much for the reply, everything works great now!
hello i tried using this video to make a platformer type game. but when i try to put the sctipt in the rooms it says "Can't add script component'room' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." pls help
Make sure the script in unity has the same name of the class in the script.
@@BenBonk ty it worked. thanks for the answer so fast
np
@@BenBonk now i have a new problem. ok i kinda broke my game so that i had to start on a new. but now i can't get the camera to change
between the to rooms. i can see that it enables in room 2 when i go there. but the camera doesn't change. sorry for all the questions i am asking.
truly epic
Life saver !
Do you guys know why my cinemachine dont appear on top like in the video? i only get a folder in my asset. If someone could help
With the newer versions, Cinemachine no longer appears in the main menu. You’ll find it in the GameObject menu, or if you right-click on the hierarchy.
THANK YOUU BRO🙏
Wait, why can't you use a box collider?
cinemachines need a polygon
Nice
Very epic, but one thing, if you maximize camera it breaks apart
my camera doesnt stay in place it continues to follow the player
fixed it my main camera was in perspective mode instead of ortographic
Nice Video :)
Thank you
TYSM BRO
the script for people that are lazy:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cam : MonoBehaviour
{
public GameObject virtualCamera;
private void OnTriggerEnter2D(Collider2D other){
if(other.CompareTag("Player") && !other.isTrigger){
virtualCamera.SetActive(true);
}
}
private void OnTriggerExit2D(Collider2D other){
if(other.CompareTag("Player") && !other.isTrigger){
virtualCamera.SetActive(false);
}
}
}
Hi, I am a Kazakh who speaks Russian, so don’t be afraid of crooked English. So I have a problem. When I jump and move between rooms, the camera jumps, but not very noticeably. But for me it hurts my eyes, how can I fix it?
By the way, I am grateful for such a lesson, I could not find a similar one anywhere, and you are here :)
Make sure your polygon collider is the exact same size as your camera
@@BenBonk Wow you quickly. Okay, thank you, I will consider
@@BenBonk Checked, now works. Thank you so much. Now I have a new problem, it is more picky, but still. When I go from left to right of the camera and vice versa, it moves a few centimeters. This is the default camera Unity. How to fix it?
@@BenBonk or continue this camera. Sorry for so many questions
ur voice is nice
made the like button blue ;)
Cool! But how to do this with Corgi Engine? Everything is done according to the instructions, but something does not work out. Room colliders do not respond to the character.
ive used corgi engine before,, have a look at the documentation for "cinemachine zones", its exactly what this video does but within the corgi engine framework
God bless your soul
Thanks!
thank you !!!!!
that's cool
Hello. Im having an issue with the polygon colliders, I believe it forces my player into crouch mode constantly, as the jump height isnt affected and the would-be regural speed is matching my crouch speed. I used movement from this video: th-cam.com/video/dwcT-Dch0bA/w-d-xo.html&ab_channel=Brackeys Please if someone found a fix for this, lemme know, Im newbie in gamedev
make sure the polygon collider is set to IsTrigger
thx!
cool
epic
Is there a way to make this in 3d???
thx
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Room : MonoBehaviour
{
public GameObject virtualCam;
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag ("Player") && !other.isTrigger)
{
virtualCam.SetActive (true);
}
}
private void OnTriggerExit2D(Collider2D other)
if (other.CompareTag ("Player") && !other.isTrigger)
{
virtualCam.SetActive (false);
}
}
How to make it without Unity?
Thanks!