Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 2D game zoom out when trigger activated

Discussion in 'Getting Started' started by Alafandri, Aug 29, 2023.

  1. Alafandri

    Alafandri

    Joined:
    Mar 13, 2022
    Posts:
    2
    Hello! So I have trying to find how to make a trigger that will zoom out your camera when activated and zoom back in when not triggered. I have been looking for something that could work but haven't found anything yet. I just can't seem to find any forums about it or a video how to create it! if you can help me then please do:)
     
  2. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    A youtube search of "unity 2d zoom camera" fids a whole bunch of things.
     
  3. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    435
    The camera is like any other game object at the scene and you can change its position. Start by making a logical framework.
    1. What do I want to do?
      I want to create a zoomable camera.
    2. Where can I find similar things?
      When I grab my mobile phone and stick the camera to something close it zooms in, when I stick it away it zooms out. So I need ZoomIn and ZoomOut methods in the class CameraController. I already wrote my class backbone.
    3. What is simple mathematical logic?
      The camera moves from point A to B and from B to A. Maybe I can set invisible game objects with the names CameraZoomIn and CameraZoomOut? Now to my CameraController, I can add references to them, so if they change in time they update to?
    4. How do I want to see this in my game?
      1. The camera jumps from A to B and back.
        I will just write in the ZoomIn method to change my camera position to the CameraZoomIn game object. I do the same with the ZoomOut method and the CameraZoomOut.
      2. The camera moves smoothly from A to B and back (how to make linear interpolation).
        If it's a move I need to add a speed parameter to my CameraController class and I need to Update the position of the camera on each screen frame. I use search how to move from point A to B and I know it's Vector3.Lerp .
        https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
    5. Now I can use my CameraController to call ZoomIn and ZoomOut any time I need, by default by some trigger it starts in another script like PlayerController.
     
    Last edited: Aug 29, 2023
  4. Alafandri

    Alafandri

    Joined:
    Mar 13, 2022
    Posts:
    2
    I didnt find anything like that