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 How to manually and smoothly pan a cinemachine vcam while retaining confiner functionality?

Discussion in 'Cinemachine' started by UWSUMUT, Dec 4, 2020.

  1. UWSUMUT

    UWSUMUT

    Joined:
    Jul 14, 2020
    Posts:
    8
    Hello,
    I'm developing a 2d mobile game and using Cinemachine's framing transposer to follow the player gameobject. I have a bigger bounding shape for the confiner extension. These work fine and smooth as well, I have no problem with these.

    The problem is my game has a level-editing stage where I allow the user to pan the camera manually via touch.
    I disable the framing transposer and use SmoothDamp on VCam's transform to move the camera by touch, it works fine as well. The problem is, as many of you know, if you manually edit the position the VCam's transform.position goes outside the confiner's bounding shape but the corrected position stays inside the shape.

    I've solved it like this:
    Code (CSharp):
    1. if (_confiner.CameraWasDisplaced(_vCam))
    2.                 _transform.position =  _vCam.State.CorrectedPosition;
    This works, but it feels choppy due to repositions after the displacements even if you use SmoothDamp with this one as well. And when it hits the boundaries, CPU usage increases due to the confiner.
    (Maybe I should calculate the potential future position first and act according to it instead?)

    Anyway, this feels like a ghetto implementation instead of a good and better solution. Isn't there any internal method to manually move Cinemachine VCAM smoothly inside a confiner when you disable the framing transposer? Cinemachine's own movement system looks a lot smoother.

    I also tried another ghetto implementation by putting a blank game object and panning it via touch then making the VCAM follow it. It was smooth but the movement was kinda problematic from a player's perspective :)

    Notes: Vcam is set to LateUpdate and the touch panning method works in a LateUpdate as well. Parallax movements in my scene are also done in LateUpdate.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    I like the empty GameObject solution. It's very simple and clean. What exactly is the problem with it?
     
  3. UWSUMUT

    UWSUMUT

    Joined:
    Jul 14, 2020
    Posts:
    8
    Thanks for your answer,
    I solved it via GameObject method, added some lines to make it work clean.
     
    Last edited: Dec 7, 2020
    Gregoryl likes this.