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

Setup top down camera where camera moves when character hits edge

Discussion in 'Cinemachine' started by AsahiChaser, Sep 20, 2017.

  1. AsahiChaser

    AsahiChaser

    Joined:
    Sep 20, 2017
    Posts:
    3
    Hi,

    So I have been trying to setup a camera that is a topdown camera - following my player character. I want the camera to stay at a consistent distance and angle from my player, and only move when the player gets close to the edge (So very much like a standard 2D camera).

    I have been able to set up something approximating this using Cinemachine - but it doesn't quite behave as expected. Using a virtual camera, with the lookat and follow set to my player character, the camera (with default settings) always tries to keep the player character in the center of the screen.

    Interestingly - by removing the Follow reference to the player (on the camera) - the player will move to the edges, and then the camera tracks correctly. But of course, the camera will never move from it's position.

    always-center-2.PNG

    Even when the player character moves - it stays in the center, never reaching the edge... I want the camera to move only when the player hits the blue line - but the camera should stay in the same orientation and follow the player.
    always-center.PNG

    Any help would be appreciated!
     
  2. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    We've recently found a bug where the object stays stuck in the middle even though the blue guides are far aside.. Can you try hitting play and or restarting Unity?

    We've run into this once before, it seems like a super rare bug which pops up sometimes and we can't track it down.

    Please try that and let us know.

    When it starts working again - and it will! - this is a weird sometimes bug, take note of the Word Up Override feature on the Cinemachine Brain. CM is designed to shoot things flatly, like a camera person shooting things on the horizon. Looking up and down can get into gimbal lock areas, which we address but it's outside the 'nice' zones for the math.

    World Up Override will allow you to rotate the 'horizon of nice math' to be downward to match your game
    upload_2017-9-20_8-38-48.png
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
  4. AsahiChaser

    AsahiChaser

    Joined:
    Sep 20, 2017
    Posts:
    3
    Thanks for the advice - I had a look at what you suggested (I configured a world up override), but I don't think that was the primary issue. The camera angle, while downward, was not perfectly downward, and even in more shallow situations - it would still be a problem.

    But thanks again. :)
     
  5. AsahiChaser

    AsahiChaser

    Joined:
    Sep 20, 2017
    Posts:
    3
    This is it - works perfectly. Thanks so much for the suggestion - it took longer for the package to install than to configure it. ;)
     
    Adam_Myhill and Gregoryl like this.