Search Unity

  1. New Unity Live Help updates. Check them out here!

    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
unityunity