So I haven’t really used Cinemachine much and I am not really a programmer either. I am wondering what the simplest way is to switch between cameras using “Colliders” (set to Trigger). I have a third person controller (Unity’s Third Person Controller) and I just want to be able to trigger a new camera by walking into a “TriggerBox”. How do I go about that?
Create the trigger collider box and add a CinemachineTriggerAction behaviour to it. You can set that up to activate/deactivate Cinemachine cameras or change their priorities.
There is no programming involved. Add the CinemachineTriggerAction behaviour and set it up to activate your special camera. In the illustration below, VirtualCamera will be activated whenever the player enters the trigger zone, and deactivated when the player leaves. If VirtualCamera has the same priority as your normal Cinemachine Camera then it will be live while it is active, and the CinemachineBrain will take care of blending back and forth. Try it.
Thanks! Didn’t know there was a script already provided. Unfortunately, I can’t seem to get it to work. I made sure to set everything up the way you’ve shown but nothing gets triggered and no camera switching occurs.
OK looks like the “Layer Mask” was the problem. I got the camera switching working. However, there is some serious switching back and forth happening as if it can’t decide which camera to render. That happens when the player is just at the edge of the Trigger Box.
I think the reason is that the the next Camera I switch to has a different “Forward” Vector than the previous so I keep running in opposite directions resulting in a sort of loop? Surely there must be a way to avoid that?
If I understand correctly, when you make the player move past the edge of your trigger zone the incoming camera has a very different forward vector from the outgoing one, and your player movement is relative to camera forward so it gets confused. Is that right? Why do your cameras have radically different forwards? Is that desired? If so, then you will probably need need to reconsider the player movement algorithm. If not, then maybe you can describe the behaviour you’re looking for.
I am using what Unity provides on the Asset Store (Third Person Controller). So I have no idea what the code does. I literally am just using it for convenience currently.
Surely! So currently when I walk into a Trigger zone the “Input” gets screwed up as it seems often resulting in the Player moving into the opposite direction (or some other arbitrary direction). What I do expect is that my forward direction doesn’t change. Meaning, whatever direction the player is facing SHOULD be the forward direction. So in other words the Player Z-Axis should be forward and never change. If I press “W” on my keyboard to move forward then it should always be forward no matter how the camera is positioned.
ok, thanks. I get that part. Now please describe what you would like to happen when the boundary is crossed and the camera changes. Where is the outgoing camera? Where should the incoming camera be? What effect would you like to achieve?
Currently I just want that the character moves in the Z-Axis at all times moving forward regardless of Camera orientation or which camera is being used. When I enter a new Trigger-Box I would like a hard cut. No fade in or outs or anything fancy. Just hard switch (imidiate switch to next camera).
The way games that used the camera system you’re describing was to either use “tank controls” (forward is always the local forward of the character you are playing and left right would make the character stop and rotate). I believe the first Silent Hill controlled like that and it was an option for some of the later ones.
The other solution, if you want to use camera relative forward vectors is that: Upon change of a camera, you DON’T re-evaluate the forward vector (you keep the old one), until a new button is pressed or if it’s a controller, the joystick is moved over a threshold. So if you’re holding down “W”, if you keep it hold down, you keep moving with the old vector until you either press another button, or you let go “W” and re-press it (at which point the vector changes to the forward of the current camera).
AFAIK, Unity’s controllers + Cinemachine don’t really allow you to do that (correct me if I’m wrong).
I think Cinemachine can handle the static camera switching (although it’s probably overkill for that, but if you’re looking for 0 coding solution you don’t have many options), I don’t think the controller you’re using can do tank controls.
Cinemachine is compatible with tank-type controllers. You said you were using the 3rdPerson controller from the asset store. That’s not a tank controller. Get rid of it and use a tank controller instead.
Alright so I did some work and got a “Tank” style Controller set up as well as Cinemachine Virtual Camera’s to blend/switch between various cameras. Seems to be working nicely now! Here is my little test scene/setup. Everything is just placeholder art of course but I am pretty satisfied with how it feels/looks! Thanks for the help guys!