Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Virtual camera going out of collision bounds

Discussion in 'Cinemachine' started by SYNYSTER, Feb 13, 2020.

  1. SYNYSTER

    SYNYSTER

    Joined:
    Jul 13, 2011
    Posts:
    21
    My game is 2D and top down. When I pan my camera the camera stops at the collision bounds of the confiner, but the virtual camera keeps going. I tried a few different things, but nothing worked. I can't find any information when I search about changing the position when following nothing. Not sure if there is a better way to move it. Thanks for any help!

    Code (CSharp):
    1. Vector3 direction = touchStart -Camera.main.ScreenToWorldPoint(Input.mousePosition);
    2. vcam.transform.position += direction;
    Solved by doing

    Code (CSharp):
    1. Camera.main.transform.position += direction;
    2. vcam.transform.position = Camera.main.transform.position;
     
    Last edited: Feb 13, 2020
  2. agmcorp

    agmcorp

    Joined:
    Jul 25, 2019
    Posts:
    3
    I have exactly the same issue.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Why do you need the vcam position? It's the main camera that matters - use its position.