Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cinemachine Camera is off center and won't follow character?

Discussion in 'Cinemachine' started by ethanbradley56, Dec 20, 2020.

  1. ethanbradley56

    ethanbradley56

    Joined:
    Dec 20, 2020
    Posts:
    3
    Hey everyone! This is my first unity forum post so let me know how I do :)

    I just started using Unity and I'm having some problems. I got a script going that lets me use arrow keys to move my character, and it'd be really great if the camera could center on and follow the character right? Unfortunately I told my cinemachine camera to follow and look at my little guy, but when I enter play mode the camera stays still and I can even move my character offscreen. It's also off center of the character as seen in the picture. I uploaded some pictures I hope will help, and I am very willing to provide more information!

    What's not wrong:
    +Everything in the scene (red dots) is centered to (0,0), so everything should be centered (I think)
    +Everything I've talked about is the same in playmode and out of it (I'm making changes in the right mode)

     

    Attached Files:

  2. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Hey @ethanbradley56 and welcome to the forum!

    Very well indeed! The only improvement I might have added would be Unity version and CM version...but I think I can help in this case, even without those. I should note, though, that I'm the "B" team. Most of the engineers are on break for the holidays. I'm just the Product Manager but hopefully I'll muddle through.

    The most notable issue here is the lack of a CinemachineBrain on your Camera. This should have been instantiated automatically when you created your VCam. The fact there's not one there is a bit of a mystery to me, but try adding one manually: select your Camera; in the Inspector, click Add Component; type 'CinemachineBrain' and click on it. As near as I can tell from your setup, that should fix you.

    Note that for a 2D game, there's usually no need to set the 'LookAt' property on your VCam.

    Hope that helps!
     
    ethanbradley56 and Gregoryl like this.
  3. ethanbradley56

    ethanbradley56

    Joined:
    Dec 20, 2020
    Posts:
    3
    Thanks so much for the quick reply Marc! Your suggestion totally fixed my problem!

    I remember now that when I was setting up the Virtual Camera I was confused about how it worked and I deleted the original Unity Camera and remade it. I'm sure the original camera I deleted had the brain, and the new one obviously didn't. Also, the LookAt feature was doing some wonky things in my 2d game and thanks to your comment I was able to figure that out right away too. For anyone in the future that sees this, I'm on Unity 2019.4.16f1 Personal and Cinemachine version 2.6.3 :)

    I'm still having issues though with the Virtual Camera not being centered on the character, despite everything being at 0,0. I can't seem to find a way to center the character besides manually adjusting "Screen X" and "Screen Y" (be default they are at .5 for me). Any help would be appreciated!
     
    Last edited: Dec 21, 2020
    marc_tanenbaum likes this.
  4. ethanbradley56

    ethanbradley56

    Joined:
    Dec 20, 2020
    Posts:
    3
    Quick update to that, my character is centered on the screen now. I reset the scale at the top of Unity (between Free Aspect and Maximize on Play) to 1 and then any subsequent adjustment kept it centered. I have no idea why it worked but it did! Thanks again for all the help Marc!
     
    marc_tanenbaum likes this.
  5. Huppertz

    Huppertz

    Joined:
    Apr 26, 2021
    Posts:
    1
    Not gonna lie I had been looking everywhere for a fix to the same issue and yours was the only solution. What a stupid issue with a obvious yet obscure solution lol
     
  6. stoikstudiosco

    stoikstudiosco

    Joined:
    Aug 4, 2022
    Posts:
    1
    I had the same issue here, after troubleshooting for a bit I realized that I had made an 'empty' game object to put all my player components in. I reset the transform on the player, and Cinemachine all together. Deleting and adding the camera over and over

    .. after further examination the transform had stayed on my object, and not only that, Cinemachine wouldn't follow an empty game object even with my player inside. So I took the player out of it. Now the camera follows and I can freely move it around. My dumbass, lol.
     
    KeusD likes this.