Search Unity

2D fighting game camera

Discussion in 'Cinemachine' started by a-t-hellboy, Nov 6, 2018.

  1. a-t-hellboy

    a-t-hellboy

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

    I'm creating a fighting game and I want to know if it is possible to create camera by Cinemachine. like Skullgirls and other fighting games. something common between fighting games.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Yes, of course it is!
     
    a-t-hellboy likes this.
  3. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @Gregoryl Hmmm, I don't find anything useful. can you provide any links ?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You can start here:
     
  5. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    I've seen this video but it's not really good enough for my need. I hope you understood what I want. It is hard to explain clearly but let me explain a little about it.
    First if all, best reference for it is Skullgirls camera system. camera looks at both characters in the stage and camera move according to them. There are zoom in and zoom out but they have limitation.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You need to use CinemachineTargetGroup for this. Create a GameObject, add a CinemachineTrgetGroup component to it. Then add your characters as members of the group. Use the group as the vcam target. You'll have settings in the Framing Transpooser to control how the group is framed on the screen.
     
    a-t-hellboy likes this.
  7. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Thanks @Gregoryl for the hint. I've changed some of variables value in Framing Transposer. I just figured it out I should use FixedUpdate Update Method in Cinemachine Brain for decreasing lag on the camera because I use physics for moving characters in the game. But now, those dead zone or damping have no effects. Why ?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    There was a bug in some CM versions that killed the damping if the Brain was set to Fixed Update. Upgrading CM should fix this.
    However, everything should work correctly if you leave the Brain in SmartUpdate.
    You should set the TargetGroup update method to Fixed.
     
  9. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    I have 2.2.7 version and I guess it is up to date.
    Yup, I've changed TargetGroup to FixedUpdate and Brain to SmartUpdate but I have other problems. Sometimes camera has weird behavior. Also by SmartUpdate when I go to end of the screen and zooming out is started it has some delay to go to target zoom although the damping is zero.
    I want no damping when zooming in or zooming out is started and when camera is at its min ortho size little movement of character doesn't effect camera. By changing variable I don't find the correct result.
     
  10. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    That weird behavior is when camera starts zooming out then back to zoom in the camera position is not same as the beginning.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It's a little hard for me to mentally visualize all this without context. Can you export a small package that shows this behaviour and post it here?
     
  12. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    If it is possible first answer this question then I try to make something and pot it here.
    My 2D characters rotate to 0 or 180 according to direction of movement and if camera target object for each of them in target group is not at the center of them by changing movement direction I have camera jump so I have to put camera target at the center of them. So when characters try to get distance from each other camera zoom out starts from center of the characters. Do you have any solution for it ?
     
  13. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    @a-t-hellboy I don't really understand what the problem is. Camera target is at the center of the character. When camera zooms out it zooms out from there. What is the problem?
     
  15. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @Gregoryl Okay, it is a sample project.

    Right player moves with ASDW and jump with space and left player moves with arrow keys and jump with right ctrl.

    As you see players rotate to their movement direction (By changing their Y rotation to 0 or 180).
    If I put camera target in sides not center of them when they change their movement direction, camera has a little change like zoom in/out or move. So I put camera target in their center but when center of them reach end of the screen, camera zooms out which it doesn't look good because camera should zoom out when whole the sprite is at the end of the screen.

    I want camera zoom out when first pixel of the sprite is out of the screen not half of it and when player changes its movement direction, camera won't have any sudden zoom in/out or move.
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Yes, now I understand the problem.

    Leave the target in the center of the shape, and give the targets a radius in the Group. That way the vcam will know how big they are and will frame them properly:

    upload_2018-11-9_16-16-5.png
     
    a-t-hellboy likes this.
  17. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @Gregoryl Thank you very much.

    Now I have some problems. Look at this sample which is updated by those radius values. As you see when both players move away from each other (the camera is zoomed out) then they get close (the camera is zoomed in) but (1) camera is a little upper than start of the game and (2) sometimes framing changed (Just move them together and you can see this problem)

    Also when the game is started (3) there is a little jump in the camera and it is moved to the correct position.

    Another problem is when players move to opposite side of the screen (4) framing doesn't work correctly.

    How should I solve these problems ?

    PS: I posted these gifs for not wasting your time.
    First problem: https://gyazo.com/ef204cff4d4c213ff9a0578772e1fade
    Second problem: https://imgur.com/a/Ux6BuZJ
    Third problem: https://gyazo.com/945884ef9260b81ad9b93b8aa1329ea4
    Forth problem: https://gyazo.com/d7b29029b84598b8653d293eff670003
     
  18. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You need to adjust your settings properly. The dead zone introduces variability in the framing (that's what it's for). In your case you should set it to zero. Also make sure that the screen is centered horizontally:

    upload_2018-11-12_9-23-42.png

    Finally, set the object radii accurately to get the correct framing:

    upload_2018-11-12_9-24-38.png
     
    a-t-hellboy likes this.
  20. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
  21. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey there,
    I want group framing in both horizontal and vertical axis. I changed group framing mode to Horizontal and Vertical mode but the problem is that, radius in Cinemachine Target Group changes both horizontal and vertical, Is there anything which I can change the radius for horizontal and vertical axis separately ?
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Unfortunately no, not without a lot of custom scripting
     
  23. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Gregoryl Do you know how can I add it by scripting ? I want vertical zoom back too but it doesn't work correctly with that radius.
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Maybe one way to do it without significant scripting would be to make the character radius correspond to the width of the character (horizontal size), and then add extra invisible members to the group above/below the characters, to force the group framer to include them. They could possibly just be invisible children of your player.
     
  25. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Gregoryl Unfortunately It doesn't help. By this approach I can determine width and height of target group as I requested but because group framing happens according to size of camera and Minimum Ortho Size change both width and height I can't have vertical group framing as I want.
    The thing which I want is when character jump and the other one is not visible, group framing happens and makes both characters to be visible.
     
  26. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @Gregoryl I have another question.

    How can I disable camera movement on Y axis but movement and framing is active on X axis ?
     
  27. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I'm having some trouble wrapping my head around what you're trying to do. Could you post some pictures or diagrams to illustrate the camera behaviour you want?
     
  29. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @Gregoryl I don't want any camera follow in y axis. If you remembered I use target group and group framing.
     
  30. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You want to lock the camera Y? You can use a confiner extension
     
  31. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Yup. How should I use cofiner for locking camera Y axis ?
     
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Create a 2D collider to use as the bounds for where the camera can go. Make it wide in X and tight in Y. Camera will stay inside it.
     
    a-t-hellboy likes this.
  33. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Thank you very much.

    Just there is a problem when camera is extended in X axes then camera goes out of boundary and there is a jump.

    https://gyazo.com/28b427523aa6ca9c6fd1a4e9052deb2a
     
    Last edited: Dec 17, 2018
  34. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Confiner only works if camera rectangle fits inside the confining shape. When you grow it, it becomes too big and stops working. Now that I understand better what you're trying to do (thanks for the graphic), I can see that the confiner will not work for your needs. You'll need to write a custom CinemachineExtension that forces the camera to stay on the ground.
     
    a-t-hellboy likes this.