Change camera on entry collider.

I’m working on an RPG game and what I want to accomplish is that when the player enters a collider the camera changes to a preset different camera. Because normally the camera is focused on the player its self.

For example in an area that has a nice view the camera switches to a different camera that has a better perspective of the player and the view.

So when you enter the collider it switches to that special camera and when you leave the collider it switches back to the normal camera.

Is there any way to accomplish this with cinemachine currently, or is there any script that can help with that?
Like a way to tie the activation of a camera to the trigger of a collider. With some script i can add to a collider which specifies which camera it needs to activate on collision.

-Wolf

Hello,

You can have multiple Virtual Cameras in the game world at the same time. Your camera will use the first VCam with the highest priority.

Basically, this setup just switches between camera views. How the VCams are set up is still up to you:

  • Gameplay VCam, priority 10
  • Special VCam, priority 9
  • Camera with CMBrain

Then when entering the collider, you can change to Special VCam’s priority to 11. This will cause your camera to transition towards the Special VCam’s settings.

Set Special’s priority back to 9 when you exit the collider to return to the Gameplay VCam

Hope this helps!

1 Like

Yes, what @sevensixtytwo says is correct.

Cinemachine comes with a helper script to facilitate this. Create your trigger collider, then add the CinemachineTriggerAction component to it. You can set it up to boost the vcam’s priority when the player enters the trigger, and un-boost it when the player leaves. Or activate/deactivate the vcam. All without coding.

4756205--451682--upload_2019-7-17_8-38-53.png

2 Likes

Ughh I’ve got a headache by looking to solve this problem.

1 Like

Heres a way to do it using a C# script although it does have its limitations.

Create a script, copy and paste this C# text into it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class CamColWorld : MonoBehaviour
{
    [SerializeField] CinemachineVirtualCamera InitialCam;
    [SerializeField] CinemachineVirtualCamera ChangeCam;

    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            ChangeCam.Priority = 1;
            InitialCam.Priority = 0;
        }
    }
    public void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            ChangeCam.Priority = 0;
            InitialCam.Priority = 1;
        }
    }
}

Make sure your player object has the tag “Player” and attach this script to your collision object and make sure your collision object is a trigger, tag the box that says trigger.
Remember to change the priorities to numbers that best suit your project.
Last but not least; drag your virtual cameras into the ChangeCam and InitialCam box’s in the inspector.
The ChangeCam is the camera you want to change when inside the collision box and the InitialCam is the camera you want to change back to when you leave the collision area.

The “OnTriggerEnter” method runs code when your player is inside the collision box and the 'OnTriggerExit" runs the code when you leave.

The advice from @sevensixtytwo and @Gregoryl is also fairly solid!

Hope this helps!

Hey,
I’m very new to the coding part of Unity. I’m hoping someone could help me out here. After looking through all the solutions, the one that worked for me was the script given by @ThatMellon .
I have 4 Cinemachine Virtual cameras. Instead of going to the “ChangeCam” that I’ve picked, it goes to another Virtual camera. Should I be changing the script?

I suggest that you use the CinemachineTriggerAction behaviour instead of a custom script. No need for coding.