Search Unity

Change ScreenX value in runtime

Discussion in 'Cinemachine' started by Etirps, Apr 16, 2018.

  1. Etirps

    Etirps

    Joined:
    Apr 16, 2018
    Posts:
    14
    Hello everyone,

    What I want to do is that when I move the player left or right the value of ScreenX (Body -> Framing Transposer) should change from 0.5f to e.g. 0.15f.

    What I do:
    - added three new variables in CinemachineFramingTransposer (m_targetPos2DX, m_targetPos2DXMin, m_targetPos2DXMax) to check if the yellow point is out of the rect;
    - I check in my script the position of yellow point and change ScreenX according to point position;

    I must say that the effect I earned does not fully satisfy me. Any advice how can I do this better way?
     
    d2clon likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Why don't you just make a bigger dead zone instead?
     
  3. Etirps

    Etirps

    Joined:
    Apr 16, 2018
    Posts:
    14
    My point is that I wan't to show more scene for player according which direction he's actually walking.
    But the most important question is that my idea is good or bad? Should I change ScreenX or do something else?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Did you try using Lookahead? That's what it's for.
     
  5. Etirps

    Etirps

    Joined:
    Apr 16, 2018
    Posts:
    14
    Yes, I was working around with this but it's only working good when player's running. When he's walking camera isn't so much in front of him. Maybe I'm doing something wrong..
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    You'll have to better describe the behaviour you're looking for. Certainly you could animate the Screen X position as a function of character velocity. I would do that in a separate script alongside the vcam, instead of hacking the FramingTransposer. Your script can access the FramingTransposer like this:
    var transposer = vcam.GentCinemachineComponent<CinemachineFramingTransposer>()
     
    Last edited: Apr 17, 2018
    via_w likes this.
  7. Etirps

    Etirps

    Joined:
    Apr 16, 2018
    Posts:
    14
    What I'm looking for:
    Player stays and don't move. Camera's in the middle of the scene. If he moves to the left or right side od the screen and camera point is out of the DeadZoneWidth, I want to change ScreenX respectively to the direction he's going and show more screen in front of him.
    I know I can access to the FarmingTransposer but I can't get the values when the "yellow point" is out of DeadZoneWidth.
    I'll check your idea with animate the ScreenX position.