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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Help with freelook camera

Discussion in 'Cinemachine' started by Kvothe_Complex, Jul 15, 2020.

  1. Kvothe_Complex

    Kvothe_Complex

    Joined:
    Jul 10, 2020
    Posts:
    4
    Hello all!

    Looking for a way to lock the axis of a free look camera unless input is given. Currently I have a freelook camera set up for 3rd person. Its set to follow a created game object (holding animator, character controller, move script, etc etc.) and look at my actual player which is the child of my game object and is just the 3d model with no components. Everything works like I want except the freelook(3rd person camera) tracks mouse movement all the time. Im looking to lock the cameras axis unless the right mouse button is being held down as if the character is looking straight ahead and holding the right mouse button allows him to look around. Hopefully this makes sense. Im very new to unity and to coding and appreciate any and all help guys!
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi,
    LockedVcam:
    Have a look at our third person camera examples - checkout 3rdPersonWithAimMode or AimingRig. These rig setups are going to provide a locked behaviour.
    Or, you can create another Freelook camera (exact copy of the one you have), and set the following:
    Orbits -> Binding Mode -> Lock To Target With World Up.
    Heading -> Definition -> Target Forward
    Heading -> Bias -> 0
    Delete the Input Axis Name for X and Y axes.
    See the attached image.

    FreelookVcam:
    For this, you can use your Freelook camera, or checkout the DualTarget example scene.

    You could blend between these two cameras depending on user input. If the user is holding the right mouse button then FreelookVcam is active, otherwise the LockedVcam is active.
     

    Attached Files:

  3. Kvothe_Complex

    Kvothe_Complex

    Joined:
    Jul 10, 2020
    Posts:
    4
    Thanks so much for the response and direction! Im excited to try this out and will have to look into blending between cameras as I haven't ever done this. I assumed the only way to accomplish my goal was through locking the freelook camera axis in the script and providing an if statement for input.button(right mouse) to unlock it. I will definitely have to play around with the cinemachine settings more and look up camera blending
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You can switch between cameras by changing the priority property on them (you can also enable the vcam you'd like active, and disable the rest). The highest vcam is going to be picked. Blend happens when cameras switch. Blend behaviour is set on CinemachineBrain (see DefaultBlend and CustomBlend properties).
     
  5. Kvothe_Complex

    Kvothe_Complex

    Joined:
    Jul 10, 2020
    Posts:
    4
    So I guess I went about this a slightly different way but its working great now!

    I ended up cloning my 3rd person camera, disabling the axis control on the clone and then switching between the 2 using input and SetActive in script

    Edit: I did have to make the clone a child of the original 3rd person cam to set it in the exact same position and then just set the clone to follow the original and look at the player if I remember correctly
     
    gaborkb likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
    Glad you got it working. There is an alternative way to do this, which is perhaps simpler.

    Every frame, FreeLook queries the input system to see if the user wants to move the camera. By default, the Mouse X/Y inputs are used. You can intercept this call, and return 0 unless the button is down. See this thread for an example of how to do that:

    https://forum.unity.com/threads/how...en-the-mouse-key-is-down.527634/#post-3468444
     
    gaborkb likes this.