Search Unity

Camera for runner game

Discussion in 'Cinemachine' started by a-t-hellboy, Feb 7, 2020.

  1. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey guys,

    I'm trying to use Cinemachine for making camera behaviour like Sonic Forces mobile version but no success yet.



    It is a little hard to explain all the details so I just put the video link above.
    First of all, the camera follows the character and when character move sides there is a damping (Smooth movement to the target in screen x axis), the camera always looks at the character (In angles paths to the side there is a little bit side look) and other details which you can see in the video.

    So any help to implment it with Cinemachine in my game ?
     
  2. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey guys,

    I'm trying to achieve above camera motion.

    1) I have a problem which I don't know how to solve it.
    Gif : https://gyazo.com/71dc0372686dc09ff96e3cd5dbd04f5e
    Setting: https://gyazo.com/60252262e15842901cfb383d375dc3ec

    As you can see in the gif camera look at the cube. I don't want that smooth rotation when the cube changes its lane. I want exactly camera behind the cube when it changes its lane like what you can see in Sonic Forces.
    What should I do ? (Just consider the path is more complicated than just the straight path, there are turns, downhills, uphills, rotate paths and so on)
     
    Last edited: Feb 9, 2020
  3. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Anyone ?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Looks to me as though you want the camera to follow the player, but to always have the forward vector be the same as the path's tangent.

    To make that with Cinemachine, I would use a FramingTransposer in the Body, and DoNothing in the Aim. Then, make a custom script to derive the camera's rotation from the tangent of the path under the player, and apply that every frame to the vcam's rotation.
     
  5. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    hi @a-t-hellboy, there's always a few ways to potentially config something. In addition to Gregory's method, you could also try a dolly track, with the camera being set to 'Auto Dolly' - follow - the players down your dolly spline.

    upload_2020-2-10_9-12-51.png

    So the setup would be
    1. Create a Dolly Camera with Track
    upload_2020-2-10_9-13-36.png

    2. Add points to the dolly track and have that align with your course path
    3. Set the camera to Look at and Follow your character
    4. Put a little Position Offset in there to have the camera follow behind your character a bit
    upload_2020-2-10_9-15-7.png

    5. Tune up your Composer Aim so there's lots of x / horizontal damping (to match the reference video). Maybe event try some Screen X/Y shape modification to get exactly the aim behavior you want.
    upload_2020-2-10_9-16-11.png

    6. For the dynamic zooming on speed, you can do that through script or with a State Driven Camera blend listening to your sprint state. Simply have the SDC trigger a slightly modified copy of your game camera with the wider zoom - maybe even get in a bit closer to keep the character the same size on screen

    Let us know how it goes.
     
  6. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey there,
    Thanks for the replies. Adam_Myhill Gregoryl
    I'm not sure if using Dolly Track is a good way because as I know (If I'm right) I should recreate track for the camera on my path which is made by spline. So it is so much work and I think it doesn't make sense (I think it will make some bugs future in my project).

    About Farming Transposer I've not tested it.

    Just consider some situations: 1) In default path in Sonic Forces there is no rolling and camera look at the character. 2) At turns the camera changes and according to the turn side, the character put on right or left side 3) At loop paths (Upside down paths) camera zoom in and other stuff. 4) When the character is sliding under obstacle the camera goes down. 5) No tracking by camera in Y axis when the character jump.

    So right now I'm using Transposer with Lock to Target No Roll and Aim Composer for the main path.
    For turns it is same but a little bit changes for putting the character in side and showing the further path.
    For loop I'm using Transposer with Lock to Target and Aim Composer.
    No camera for sliding yet. I'm working on it.
    For ignoring jumping I have cameraTarget object which it is always on path and don't changes by jumping.
    So for smoothness in changing lane in X axis I'm thinking about take more control of my cameraTarget object.

    What do you think ? Is it a correct way ?
     
  7. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Don't discount the dolly track just yet. I know it's work but to have the camera follow the track perfectly when you're only following the player moving around is a tricky thing to do.

    Taking more control of the cameraTarget object is often a very good idea. It is sometimes much easier to give the camera target some extra desired behavior to help out the camera film things in the right way. Simply using the Unity constraint system to have an object follow the player but not move in the Y axis is a great way to strip unwanted movement.

    You might be best building two sets or basic rigs on dummy objects, one for the camera to look at and the other to follow.
     
    a-t-hellboy likes this.