Help with freelook camera

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!

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.

6096933--662643--Screen Shot 2020-07-16 at 9.09.34 AM.png

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

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).

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

1 Like

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:

1 Like