Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Change ScreenX value in runtime

Discussion in 'Cinemachine' started by mr-euksinus, Apr 16, 2018.

  1. mr-euksinus

    mr-euksinus

    Joined:
    Apr 16, 2018
    Posts:
    7
    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?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,549
    Why don't you just make a bigger dead zone instead?
     
  3. mr-euksinus

    mr-euksinus

    Joined:
    Apr 16, 2018
    Posts:
    7
    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:
    1,549
    Did you try using Lookahead? That's what it's for.
     
  5. mr-euksinus

    mr-euksinus

    Joined:
    Apr 16, 2018
    Posts:
    7
    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:
    1,549
    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
  7. mr-euksinus

    mr-euksinus

    Joined:
    Apr 16, 2018
    Posts:
    7
    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.