Search Unity

Zoom in and out

Discussion in 'Cinemachine' started by VP_no1, Aug 18, 2018.

  1. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    Hi.

    I have a simple 2D Camera and I am using it to have like an isometric view in a 3D space.
    http://myprintscreen.com/s/vrz7/690a8fb72c
    In order to be able to zoom in and out, I have to implement in my code something like this ?
    https://answers.unity.com/questions/218347/how-do-i-make-the-camera-zoom-in-and-out-with-the.html
    and use from this only the update of fov += Input.GetAxis("Mouse ScrollWheel") * sensitivity; ?
    since the rest is allready in the script ?
    should i just add that update in a CInemachine script or create my own and add it to the CM camera or to main camera ?

    thanks


    ps. maybe I should create a new topic for this :)
    I didnt find an easy way to setup a freelook cam so that it follows around when i am fighting yet :) No matter the settings I use it moves too fast around or up and down or not satisfactory :( I understand usually it is needed to have more cameras, but still having a great one would suffise most of the time.
    The freelook tutorial is not for a 3rd person character but for a simple ship moving left right -- I really think there should be dedicated tutorials to implement each type of Cinemachine camera to 3rd person characters. Most games have a central character and I think the community will gain a lot from this type of tutorials.
     
  2. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    I am doing something wrong here and I need some help please.
    I tried add this to the CM vcam. Yet nothing happens.

    Code (CSharp):
    1.     public class GetZoomInput: CinemachineFollowZoom
    2.     {
    3.  
    4.         public float sensitivity = 10f;
    5.         private CinemachineFollowZoom FOVS;
    6.        
    7.         void Awake () {
    8.             FOVS = GetComponent<CinemachineFollowZoom>();
    9.         }
    10.  
    11.         void Update () {
    12.            
    13.             float fov = Camera.main.fieldOfView;
    14.            
    15.             fov += Input.GetAxis("Mouse ScrollWheel") * sensitivity;
    16.             fov = Mathf.Clamp(fov, FOVS.m_MinFOV, FOVS.m_MaxFOV);
    17.             Camera.main.fieldOfView = fov;
    18.         }
    19. }
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I'm a little confused about what you're trying to do.
    • You have a vcam that orbits around the player, but has Do Nothing in the Aim, meaning that that there is nothing that makes the camera look at the player - its rotation will remain constant as its position orbits around the player. Is that what you want? It seems rather strange.
    • You have a FollowZoom extension that is driving the fov based on the camera distance to the player
    • You are trying to add another script to drive the fov based on mouse input
    Can you describe more precisely the camera behaviour you want?

    One thing to clarify: Is it really zoom you want, or would moving the camera toward/away from the player be more appropriate?
     
  4. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    Atm with the settings I showed for the camera, I have a top camera that follows the player om X and Z axis and does nothing on Y.
    This is the basic I did to be able to play my map, because I have high walls on all 4 sides.
    I will make more cameras and make a button for the player to switch between them. So until now, I have this basic one. I would like to be able to zoom in/out this camera, keeping player in the center and of course its FOV will go lower. Unfortunately the extension does not work. My code does nothing with the camera, it just reference the main camera and nothing more.

    I would like to have other cameras too:
    - another one would be similar to the above one, but have a bit more perspective on the player/environment, keeping the player in the middle, and when colliding with something (walls) it should tilt on Y ax so it keeps the player in the center. Of course after player goes back to its initial distance from the camera, it would begin to move again (I think here I need a dolly + a free look :) ?)

    - and the most important one I would like would be a third person camera that is always behind the player and orbits around it so that regardless how much i zoom in/out of the player, I have the camera on constant Y value to his head (i think in the oribt rigs i have to put them follow the head of the player). Furthermore, when I max zoom in I want my camera view to change to 1st person camera - do I need to setup another camera for this ? And of course when hitting colliders in the back it should zoom in to max (so it enters a 1st person camera).

    ps. Sry for not expressing very clear. I hope now it is more clear (I didnt thought before that I would need more cameras to actually do different stuff and cannot have all in one :) ).
     
    Last edited: Aug 21, 2018
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    @VP_no1 Thanks for clarifying but unfortunately I am more confused than ever. I cannot tell from your description what you are trying to do, and I cannot make it match what you have showed me. Maybe you could draw some simple pictures?

    Always behind + orbits around = contradiction
    FreeLook + dolly = contradiction
    Zoom in to max + first person camera = contradiction
    "My code does nothing with the camera" + "Camera.main.fieldOfView = fov;" = contradiction

    4 * contradiction = confusion

    If someone else on the forum understands the requirement, maybe they can help?
     
  6. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    @Gregoryl
    Got your point :)

    1. most of the time behind the player on a X distance, but when it hits a back object, it will rotate on the right side, keeping same distance to the player's body (so character is always in frame)
    2. 2 different cameras to be switched when the event happens
    3. when i zoom closer to my target i want to zoom until i have a vision of a FP camera (do I need to switch here to another camera ?)
    4. leave that code aside // I said that with just the Cinemachine zoom extension, the zooming does not work

    If it is still unclear, I will try get some pictures later on.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I know you're trying to describe things, but I just get more and more confused. Let's start at the beginning. Let's first get onto the same page about your game.
    1. Player walks around on a 3D terrain.
    2. There are high walls on this terrain.
    3. You have several different cameras that you want. Let's concentrate for now on the first one only:
      1. Camera looks from above. Is it pure top-down, or is there a slight angle?
      2. How far above the player is the camera?
      3. Camera follows the player, so that as the player moves the camera follows along, keeping the player in the center of the screen.
      4. Does the camera turn with the player, or remain fixed as the player turns?
      5. Is this top-down camera orthographic or perspective?
      6. You want to add zoom to this camera. If it's orthographic, that means changing the ortho size. If it's perspective, then you have 2 options: change the FOV or change the camera-to-player distance. Which one do you want?
     
  8. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    1. yes
    2. yes
    3. --
    .1 looks from above // slight angle + a bit behind the player
    .2 check here: http://myprintscreen.com/s/w6nj/bdc61b795e
    and here: http://myprintscreen.com/s/w6p1/94b157397b
    .3 "as the player moves the camera follows along, keeping the player in the center of the screen." >> this one
    .4 i want it to turn with the player but smooth (for not turning, i just did AIM do nothing)
    .5 perspective
    .6 change the camera-to-player distance >> this one

    * .4 (if i have aim composer I see it does so but it is strangely moving and my moving controls are not keeping their behaviours and so is the fire direction -- i am setting up something wrong 100% )
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Alright then, for the first vcam you need:
    LookAt and Follow targets = player
    Body: ordinary Transposer (NOT orbital), binding mode = Lock to Target with World Up, offset = Vector3(0, +big, -small).
    Aim: Composer. Make sure the camera is not exactly on top (i.e. make sure the transposer's Z offset is non-zero), or the aim will not function properly.
    To adjust the camera distance: scale the Transposer's offset vector. You can do that in a custom script in response to mouse wheel movement.

    Once you have this working, we can discuss the next camera you need.
     
    Last edited: Sep 4, 2018
  10. VP_no1

    VP_no1

    Joined:
    May 12, 2018
    Posts:
    132
    I have a hard time at work and 0 time for now to test all you wrote. I will get back with feedback the soon as I can continue this project.
    So atm I dont have a clear answer on the above.
    Thank you a lot!