Search Unity

Resolved 3rd Person aim: The best way to control the second camera

Discussion in 'Cinemachine' started by GUSRG, Sep 16, 2020.

  1. GUSRG

    GUSRG

    Joined:
    Feb 29, 2020
    Posts:
    6
    Hello everyone,

    I'm making a 3rd person shooter game and I have been using Cinemachine for some days, I like quite a lot.
    My main references to make this project have been the 3rd Sample Scene found on Cinemachine files, one of Breckley's 3rd person video and another Unity tutorial video. (Most of the code is a adaptation of Breckley's code with my own)

    Just to keep in mind, all my project is a prototype and so far only the controller works.
    Camera 1 is called Cinemachine
    Camera 2 is called CM StateDrivenCamera with a gameobject called CM vcam1 inside.

    So far my main Cinemachinecamera is working very well, the camera is set close to the right shoulder of my character while walking/running around. I'm trying to make a camera very similar to Resident Evil 2 Remake while aiming.

    The problem are:

    -When my character aims, I set to my second camera to be a bit more closer to the character while aiming, the transitions between the first camera and the second one is smooth (the speed is a bit slow and I don't know how to change it).

    - While aiming and rotating my character looks like it's shivering and sometimes he get off screen.

    - I'm not sure if I choose the second camera to be the correct one. I didn't know how to make this transition from Camera 1 to Camera 2 (and vice versa), so the best way I found was to use a gameobject.SetActive script that disable the first camera.

    ---
    In order to make my problems a bit more clear, I made a video to show it:



    If I did goofy on that CM StateDrivenCamera, I'm sorry, but I didn't found another way to do it. Most of tutorials cover other angles or other kinds of camera, and StateDriven was the way I found to achieve the solution, if anyone can point me at the right direction, I would be very glad. :)
     

    Attached Files:

    • 001.png
      001.png
      File size:
      12.1 KB
      Views:
      364
    • 002.png
      002.png
      File size:
      69.3 KB
      Views:
      355
    • 003.png
      003.png
      File size:
      51.1 KB
      Views:
      354
    • 004.png
      004.png
      File size:
      65.5 KB
      Views:
      354
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You can customize the transition/blend time in CinemachineBrain. Create Custom Blends using the Create Asset button. See the attached CMBrainBlends.png.


    It is due to damping parameters set on your virtual camera (vcam). Instead of using your current setup, I suggest you to take a look at our example scenes called 3rdPerson... You can get our example scenes from the package manager, see the attached ExampleScenes.png for more info.
     

    Attached Files:

    Last edited: Sep 16, 2020
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    If I understand correctly, in your game you'd like to use 2 type of cameras: one for moving around, and one for aiming.

    If you have animation states for "aiming" and "moving around", then you could use state driven vcam. You'll need to tell state driven vcam that on state Aiming, switch to aiming vcam, else use the moving around vcam.

    You can also just trigger the change from script by hand. If you are aiming, then Active the aiming vcam. If you are not aiming, then Active the "moving around" vcam.


    This is a good way of doing it.
    You can also change the priorities on the vcams. CinemachineBrain will select the vcam with highest priority.
    For example:
    • vcam1 priority 9, vcam2 priority 10 -> vcam2 is active.
    • vcam1 priority 10, vcam2 priority 9 -> vcam1 is active.
     
  4. GUSRG

    GUSRG

    Joined:
    Feb 29, 2020
    Posts:
    6
    Thanks for the help gaborkb,

    This was one of the things I was really looking for, the CMBrain made the transitions perfectly. I had completely forgotten that this CM script exists on Main Camera.

    I manage to make the camera transitions removing just the VCAM from the StateDriven (since I'm not using animations to switch cameras) and attaching to the character on the correct position. After that I made a script that rotates the Aim Camera up/down with a clamp. Now everything looks so perfect :D

    Once again, thank you!!!
     
    Last edited: Sep 17, 2020
    Gregoryl and gaborkb like this.