Ah man! thank you for this tutorial! Been wanting to swap camera positions with a trigger collision. I'm pretty new to using Unity and coding in C# (I've used other similar languages like GML). I want to learn how to manipulate the objects I put in my game with C# as a way to learn both C# and understand unity's components. All the other tutorials I've found tell me to use the "animator editor" in unison with a state based cinemachine object. But I feel a little overwhelmed with all these different features included in Unity. I noticed in the cinemachine virtual camera component; there's a priority variable. For the past few days I've been scouting the internet; with badly phrased questions thrown into google; on how to change that priority with a C# script. This works the way I want it too! Thanks again for this awesome tutorial! You've earned yourself another sub!
Hey Paul thanks a lot for your comment (and the sub!). The problem with stuff like this is there is no "right way" to do stuff, just the ways that work for the individual and their needs / skill level - it can be disheartening until you find the thing that "clicks" and I'm glad I could be part of that for you!
@@DanPos That’s the truth! Game dev is so broad, It’s pretty easy to get lost with all the different ways to do things. Eventually I’ll figure out the the animator; it looks like it could be pretty useful (maybe even save me time in the long run), but for now, I’ll stick to what I’m comfortable with. Seems to me there’s always something new to learn which is kinda exiting but I’ve been overwhelmed multiple times. Every time I feel I’ve gotten used to unity’s interface, something new pops up to confuse me 😂 Anyways; Thanks again, you’ve been a huge help!
Just a thing I noticed, politely of course. You don't really need "&& c.Priority != 0" in there; after optimization it's likely to compile to equal complexity; and on any CPU from the twenty first century, I imagine it will have negligible affect on code speed. I do understand what you're saying, but by adding the if statement we're adding a JNZ to the assembly, which ought to take up just as much time as actually setting it to zero. So we're dealing with two operations where we might just need one. "Premature optimization is the freakin' devil, man." -Donald Knuth, paraphrased
It's hard to think of because it's different from a main camera. If it was the main camera, I would have thought of moving one without making two cameras. Thank you for the very useful tutorial.
Cool tutorial, I just made a manager instead, used a queue for the cameras, and the new input system instead :) I think if you have like 4-5 cameras it might be used to do a dictionary of cameras with an enum of each.
Great tutorial.👍 I have a 3D third person game, using touch controls for the movement and camera movement and the starter assets playerfollowcamera prefab, which is just a virtual camera and 3d follow player in the body. I'm trying to reset the camera once I have moved the camera by rotating it during play and then teleported, the player is rotated, but the camera stays the same direction because of the brain. I think creating another Vcam2 to keep behind the player then switch to that after teleport? But then what happens when I rotate that Vcam2 and it needs resetting again to the VCam1, will the vCam1 still be in in the 1st original pos? Maybe once the camera is switched, reset the position of the Vcam1 just before Vcam2 use, or am I misunderstanding how the brain works? It's the overriding brain I'm having trouble with as it keeps the values for rotation and position, I've tried changing the rotation/pos like the player but the brain overrides, even if I disable then re-enable the old rotation/pos values reappear, tried loads of things, forcecameraposition, follow/lookAt both to null then adding bk the transforms, resetting the main camera and the virtual cameras to zero, then reactivate the brain, but the old values still appear etc, it's driving me crazy lol I think I need to understand the brain better to move forwards. Any help would be much appreciated!
Really nice tutorial. Just one little thing: I would have named the virtual cameras virtualCamera/virtualCam or vCamera/vCam to avoid confusion since you only have one camera in the scene and the other things are not actual cameras but virtual cameras.
How do I make two cameras in the first place? I only see one MAIN camera in the video and when I make another cinemachine freelook camera my main camera goes out of whack
Why didnt you use a scriptable game object? Using static seems to be an anti-pattern according to Unity docs. If you would have used a scriptable game object then you could have multiple of this camera switchers (e.g. for split screen, or when switch from and to a cutscene)
great tutorial! but one question though is there a way to code it to a different button and not the spacebar since that button is being used for the jumping command for the character?
⏰ UNITY BLACK FRIDAY SALE ENDS DECEMBER 4th! ⚡ LIGHTNING DEALS SEE 90% OFF SELECT PRODUCTS Take 50% off the best selling assets on the Unity asset store in their Black Friday sale, now on! prf.hn/click/camref:1101lkANY/creativeref:1011l65259
Hello! Thank you for this amazing tutorial! Love this way of doing it. I had a question. If I wanted to do more cameras and assign them to different keys for different camera blends how would I add to this to do achieve this?
You would have to listen for the key press and just call the SwitchCamera function on the static cinemachine script and pass in the camera you would like to switch too. You could even have an array of cameras, keep track of array index, and swap between the cameras with the same key.
pls bro tell me how to make a ui button that when we press and hold it the camera rotates backward and shows back of the car and when we un press it it goes to its original position i want it for my car controller pls help
How can I switch virtual camera by clicking object. I'm making a gallery. That's my job. I must make it to exibit pictures, and user can see the information of that pictures. So I must make it possible, if user click one picture by mouse (basically, the view of player is first point view like FPS and horror games. In short, I call it POV.), the camera moves to closeup that and information, and if user close that UI and pushing Esc, the camera move back to the POV. But, I can't make it possible to switch camera by clicking object. Now I know how to switch camera with keyboard, because I watched this video, and I know how to make my 3D object as a button. But I don't know and and I can't find how to combine those function. I mean... I want to know how to switch Cinimachine Virtual Camera by Clicking 3D obkect. So, Can I ask you to help me? And Can you make video about that?
so button like functionality? Just add that script like imageCam.priority == 10 && NotImageCam.priority == 0; Haven't tried this myself but just a logic u can try.
You helped me BIG time! This video was the last missing puzzle to a problem I couldn't figure out.
Big thanks! 💚
Ah man! thank you for this tutorial! Been wanting to swap camera positions with a trigger collision. I'm pretty new to using Unity and coding in C# (I've used other similar languages like GML). I want to learn how to manipulate the objects I put in my game with C# as a way to learn both C# and understand unity's components. All the other tutorials I've found tell me to use the "animator editor" in unison with a state based cinemachine object. But I feel a little overwhelmed with all these different features included in Unity. I noticed in the cinemachine virtual camera component; there's a priority variable. For the past few days I've been scouting the internet; with badly phrased questions thrown into google; on how to change that priority with a C# script. This works the way I want it too!
Thanks again for this awesome tutorial! You've earned yourself another sub!
Hey Paul thanks a lot for your comment (and the sub!).
The problem with stuff like this is there is no "right way" to do stuff, just the ways that work for the individual and their needs / skill level - it can be disheartening until you find the thing that "clicks" and I'm glad I could be part of that for you!
@@DanPos That’s the truth! Game dev is so broad, It’s pretty easy to get lost with all the different ways to do things. Eventually I’ll figure out the the animator; it looks like it could be pretty useful (maybe even save me time in the long run), but for now, I’ll stick to what I’m comfortable with. Seems to me there’s always something new to learn which is kinda exiting but I’ve been overwhelmed multiple times. Every time I feel I’ve gotten used to unity’s interface, something new pops up to confuse me 😂
Anyways; Thanks again, you’ve been a huge help!
Nice one. Absolutely helpful tutorial, also easy to comprehend and helping to understand Cinemachine a bit better. Thanks and keep it up!
Hey thanks a lot for the comment! Glad it helped :)
Just a thing I noticed, politely of course. You don't really need "&& c.Priority != 0" in there; after optimization it's likely to compile to equal complexity; and on any CPU from the twenty first century, I imagine it will have negligible affect on code speed. I do understand what you're saying, but by adding the if statement we're adding a JNZ to the assembly, which ought to take up just as much time as actually setting it to zero. So we're dealing with two operations where we might just need one.
"Premature optimization is the freakin' devil, man." -Donald Knuth, paraphrased
It's hard to think of because it's different from a main camera.
If it was the main camera, I would have thought of moving one without making two cameras.
Thank you for the very useful tutorial.
Thank you for your help! )) This is really interesting and relevant material in 2023)
Brilliant tutorial. Very clear and easy to follow. Thank you very much.
Cool tutorial, I just made a manager instead, used a queue for the cameras, and the new input system instead :) I think if you have like 4-5 cameras it might be used to do a dictionary of cameras with an enum of each.
Great tutorial.👍
I have a 3D third person game, using touch controls for the movement and camera movement and the starter assets playerfollowcamera prefab, which is just a virtual camera and 3d follow player in the body. I'm trying to reset the camera once I have moved the camera by rotating it during play and then teleported, the player is rotated, but the camera stays the same direction because of the brain. I think creating another Vcam2 to keep behind the player then switch to that after teleport? But then what happens when I rotate that Vcam2 and it needs resetting again to the VCam1, will the vCam1 still be in in the 1st original pos? Maybe once the camera is switched, reset the position of the Vcam1 just before Vcam2 use, or am I misunderstanding how the brain works? It's the overriding brain I'm having trouble with as it keeps the values for rotation and position, I've tried changing the rotation/pos like the player but the brain overrides, even if I disable then re-enable the old rotation/pos values reappear, tried loads of things, forcecameraposition, follow/lookAt both to null then adding bk the transforms, resetting the main camera and the virtual cameras to zero, then reactivate the brain, but the old values still appear etc, it's driving me crazy lol
I think I need to understand the brain better to move forwards.
Any help would be much appreciated!
Thanks Dan. this video was really really helpful!
Are u working on a game atm? I am curious..
Appreciate this.
Thanks. Nice camera manager
Really nice tutorial. Just one little thing: I would have named the virtual cameras virtualCamera/virtualCam or vCamera/vCam to avoid confusion since you only have one camera in the scene and the other things are not actual cameras but virtual cameras.
You could do foreach(CVC c in cameras) c.Priority = c == camera ? 10 : 0;
thanks a lot for helping me .. huge time stucking with cinematchine property of unity ...
Glad I could help!
Great tutorial!
Thanks,
Glad it was helpful!
How do I make two cameras in the first place? I only see one MAIN camera in the video and when I make another cinemachine freelook camera my main camera goes out of whack
Why didnt you use a scriptable game object? Using static seems to be an anti-pattern according to Unity docs. If you would have used a scriptable game object then you could have multiple of this camera switchers (e.g. for split screen, or when switch from and to a cutscene)
great tutorial! but one question though is there a way to code it to a different button and not the spacebar since that button is being used for the jumping command for the character?
yes you can replace the space key with any other key
@@DanPos cool! what code would i need to replace that space button with like say "tab key" in the script file?
⏰ UNITY BLACK FRIDAY SALE ENDS DECEMBER 4th!
⚡ LIGHTNING DEALS SEE 90% OFF SELECT PRODUCTS
Take 50% off the best selling assets on the Unity asset store in their Black Friday sale, now on!
prf.hn/click/camref:1101lkANY/creativeref:1011l65259
Thank you this was perfect!
You're welcome!
Hello! Thank you for this amazing tutorial! Love this way of doing it. I had a question. If I wanted to do more cameras and assign them to different keys for different camera blends how would I add to this to do achieve this?
You would have to listen for the key press and just call the SwitchCamera function on the static cinemachine script and pass in the camera you would like to switch too. You could even have an array of cameras, keep track of array index, and swap between the cameras with the same key.
@@DanPos thank you! I will try this.
Awesome .. but how can I Aim down sight a gun in FP mode
for some reason when i do this my camera can be switched by pressing shift+ any key on the the qwerty row. :(
pls bro tell me how to make a ui button that when we press and hold it the camera rotates backward and shows back of the car and when we un press it it goes to its original position i want it for my car controller pls help
cant create a public static class, it gives me error
Thank you!!!
do i need a cinemachinebrain ?
offcourse.
In the main camera
Awesome
Put this script to good use by using it with trigger zones: th-cam.com/video/nkL-VvMmWHg/w-d-xo.html
Can I ask you to translate this to Korean?
🔥🔥🔥
im cryying in small letters... next time please consider making the text bigger so i don't have to make it full screen each time to see
My apologies!
i have the same issie haha
How can I switch virtual camera by clicking object.
I'm making a gallery. That's my job.
I must make it to exibit pictures, and user can see the information of that pictures. So I must make it possible, if user click one picture by mouse (basically, the view of player is first point view like FPS and horror games. In short, I call it POV.), the camera moves to closeup that and information, and if user close that UI and pushing Esc, the camera move back to the POV.
But, I can't make it possible to switch camera by clicking object.
Now I know how to switch camera with keyboard, because I watched this video, and I know how to make my 3D object as a button. But I don't know and and I can't find how to combine those function.
I mean...
I want to know how to switch Cinimachine Virtual Camera by Clicking 3D obkect.
So, Can I ask you to help me?
And Can you make video about that?
so button like functionality?
Just add that script like imageCam.priority == 10 && NotImageCam.priority == 0;
Haven't tried this myself but just a logic u can try.