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

2D camera zoom effect modifies transform...how to prevent?

Discussion in 'Cinemachine' started by Spacelab_Games, Jan 8, 2021.

  1. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi everyone,

    I created a zoom script for Cinemachine which increases/decreases the orthographic size of my camera but when i perform a zoom in/out effect the transform "y" position on my camera gets changed so its not aligned correctly on my player. Just wondering if there is a way to zoom the camera in/out without the transform getting modified?

    Thanks.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    can you show the vcam inspector?
     
  3. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi Gregory,

    I've attached a screenshot of my vcam inspector which displays the configuration of my camera.

    When i run my game i immediately zoom the camera in on my player (so the starting orthographic size is 40) and then the camera proceeds to zoom out until it reaches its original orthographic size of 80. Its during the zoom out effect that the transform parameters on my camera get changed - in the screenshot you will see that starting transform positions are roughly 351,-19,-10. But, after the zoom out effect is completed the transform positions become 332,-29,-10.

    So basically i would like the transform positions to remain 351,-19,-10 after the zoom out effect is completed.

    I hope this helps shed some light on the issue I'm experiencing.

    Thanks.
     

    Attached Files:

    • vcam.jpg
      vcam.jpg
      File size:
      233.9 KB
      Views:
      302
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks for the inspector. It looks ok, and unfortunately it's still not enough to determine why you're getting the transform change. A video of the effect in progress - ideally of the game view with the vcam screen guides visible - would help. Even better, if you're willing, you can send me a minimal project that repros the issue. That would save some back-and-forth.
     
  5. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi Gregory,

    Have a look at the following video footage: http://spacelabgames.com/files/videos/demo.mp4

    You will notice that as my character jumps around and lands on the ground - the Y transform position of my camera is always set to around -18. However, near the end of the video i perform a zoom in on my character and then i zoom the camera out and the Y transform position of my camera ends up being -40 - so the ground platform is significantly higher than my mobile controls. I would like the Y position of the camera to go back to -18 when i zoom the camera back to its original orthographic size.

    Thanks for your assistance so far - please let me know if you require anything further.
     
    Last edited: Jan 13, 2021
  6. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    After playing around a bit more it looks like the camera transform is being modified because of the "Follow" transform. If i set the "Follow" parameter to null in my code then the camera zooms in/out correctly without modifying the camera transform. The only issue with this now is that the camera doesn't zoom in directly on my character - the only option i can think of at the moment is adding an offset for the camera y position while it performs the zoom...which seems to work.

    I guess i can just disable the Follow object when i want more control on the camera positioning during a zoom effect.

    Gregory if you have any other suggestions I'm all ears.

    Thanks.

    -Leo
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Hi Leo,

    I think the problem is the dead zone. If the follow target falls anywhere inside the dead zone, the camera will not reframe the target - that's what the dead zone is for. When you zoom out, the character is still in the dead zone, so the camera doesn't adjust. There is no logic in place to keep the character at the bottom of the dead zone.

    I think the camera behaviour you're trying to get is that you want to the player to stay at the bottom of the dead zone, unless the player in in the middle of a jump. When the player lands on a platform, you may or may not want the camera to readjust to put the new platform at the bottom of the dead zone. I'm not sure what you want to do exactly.

    Here is one approach that might give you better control:
    • Set the vcam's vertical dead zone to 0, and put the Screen Y setting near the bottom of the screen (where your current dead zone starts).
    • Make an invisible game object, with a custom script that sets its position to always match the player's position, except that the Y is always at the level of the platform the player is currently on - think of it as the player's shadow on the platform
    • Use this shadow object as the vcam follow target
    That should give you the behaviour you want, without any weird hacks.
     
  8. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi Gregory,

    Thanks for your suggestions - i will definitely give that a try and see if it corrects the issue.

    Cheers.

    -Leo