Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it 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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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:
    70
    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:
    1,733
    Yes, of course it is!
     
    a-t-hellboy likes this.
  3. a-t-hellboy

    a-t-hellboy

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

    Gregoryl

    Unity Technologies

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

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    70
    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:
    1,733
    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:
    70
    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:
    1,733
    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:
    70
    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:
    70
    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:
    1,733
    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:
    70
    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:
    70
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,733
    @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:
    70
    @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:
    1,733
    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:
    70
    @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:
    70
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,733
    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:
    70