Search Unity

[2D] How to follow a car and having the road always visible ?

Discussion in 'Cinemachine' started by Kiupe, May 30, 2018.

  1. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hello guys,

    I'm prototyping a simple 2D (side scrolling) car game. I want the car to always be at the bottom of the screen in order to always having the car and the road visible. I'm able to do that with a Dead Zone Width and Height set to 0 and by offsetting the Screen position. But I also want the road to be visible when the car is jumping, which mean still following the car in the y position but not in the x position. Ideally the camera size should adjust in case of real big jump. Is that possible ?

    Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I thought I was understanding this question, until I came to this sentence:

    and now I'm confused. Did you mean still following in x but not y?
    If you could scribble a few pictures of what you're talking about it would help a lot.
     
  3. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    Sorry, I meant still in x and not in y. So wherever the car is, the car and the road should be visible. Does that make sense ?

    Extra question : is it possible to control the camera size depending of the target velocity ?
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You could try this:

    Let your car consist of 2 game objects: the car itself, and an invisible object that sticks to the road, always underneath the car. When the car jumps, the invisible object does not.

    In the framing transposer, target the invisible object. No dead zone. Add a little script to the vcam which adjusts the framing size according to the car's speed. That should take care of giving you enough room to see the car when it jumps.

    To set the framing size on the FramingTransposer from your script, do something like this:
    Code (CSharp):
    1. CinemachineVirtualCamera vcam = ...;
    2. vcam.GetCinemachineComponent<CinemachineFramingTransposer>().m_GroupFramingSize = bla;
     
  5. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Ok, I get the idea, thanks !

    I have not yet the right way to think of "tricks" when it comes to Cinemachine.

    Is there any plan to add new Cinemachine extensions ? When it comes to 2D it lacks a lot. It would be great to have more extensions like the ones available in ProCamera2D.

    Thanks again.
     
    Gregoryl likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's very easy to make your own custom extensions for Cinemachine. You could even share them here :)
     
  7. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    I keep that in my mind then :)
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Sorry, I misled you earlier. The group framing size only works if your vcam Follow target is a group. In your case you would just need to adjust the vcam's ortho size, like this:
    Code (CSharp):
    1. vcam.m_Lens.OrthographicSize = bla;
     
  9. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Question : would it be possible to have the VCam following the invisible object and the car itself ? Does having a group of target allowed the VCam to automatically adjust the camera size ?

    Thanks
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes you could try that