Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question can this package only move the camera when the player is at the border of the screen?

Discussion in 'Cinemachine' started by unity_005946E12C5F7D78583B, Aug 21, 2023.

  1. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    hi! im making a game and want the camera to follow the player, but, the thing it, making it ALWAYS follow the player is kind of bad (it limits a lot the visibility) so i want the camera to only move when the player is in one corner of the screen to that direction, for example, if the player is at the left cornor of the screen, i want the camera to move to the left at the same speed as the player moves, this plugin can do this or i need to use code with this?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,204
    You can do this by making multiple virtual cameras, for example one static one and one that follows the player. Activate the follow-player one when the player enters a trigger zone. Cinemachine will blend smoothly between cameras.
     
  3. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    ooooh, ok ill try that
     
  4. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    ok so im trying to use this code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Cinemachine;
    4. using JetBrains.Annotations;
    5. using UnityEngine;
    6. using UnityEngine.InputSystem;
    7.  
    8.  
    9. public class camera : MonoBehaviour
    10. {
    11.  
    12.  
    13.     public Collider2D coll;
    14.     public CinemachineVirtualCamera cam1;
    15.     public CinemachineVirtualCamera cam2;
    16.  
    17.  
    18.     private void OnTriggerStay2D(Collider2D collision)
    19.     {
    20.         if (collision.transform.tag == "player")
    21.         {
    22.             Debug.Log("yes");
    23.             cam1.enabled = true;
    24.             cam2.enabled = false;
    25.         }
    26.         else
    27.         {
    28.             cam1.enabled = true;
    29.             cam2.enabled = false;
    30.         }
    31.     }
    32.  
    33.    
    34.  
    35. }
    but it just isnt working, is there a way to activate the virtual cameras because the .enabled doesnt seem to work
     
  5. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    153
    Just a wild guess but maybe this?
    Code (CSharp):
    1.        
    2. if (collision.transform.tag == "player")
    3.         {
    4.             Debug.Log("yes");
    5.             cam1.enabled = true;
    6.             cam2.enabled = false;
    7.         }
    8.         else
    9.         {
    10.             cam1.enabled = false;
    11.             cam2.enabled = true;
    12.         }