Hello all! I recently came across using the Cinemachine Freelook camera as a third-person camera option and I really like it. Right now I’m in the very early stages of development and am playing around with options. One struggle I’m having is the ability to define how I want the camera to follow the mouse.
By default the camera locks to all mouse movement, and then re-centers automatically (after the defined delay) when I have “Recenter to Target Heading” enabled. This works very well for me, however, I would prefer it if the camera only followed my mouse if I was holding down the right mouse button, and then, when released, would begin its Wait Time timer to re-center the camera. I’ve seen this effect many times in games (WoW comes to mind most readily) and am looking to reproduce something like that.
Unfortunately I’ve come up with no good guides on how to pull this off. I was hoping it was a setting within the Brain or camera’s CinemachineFreeLook component but if it is I’ve been unable to find it.
Can anyone point me to a guide or provide some input on how I could pull this off? I would greatly appreciate any guidance, and thank you in advance!
You could disable recentering from a script as soon as the player is aiming (i.e. holding the right mouse button) and re-enable on release. Take a look at this thread: Make Player Turn Before Camera Does
After some more thought I went with something really simple. It works for me for now, but will need some further
refinement in the future. Either way, this is what I came up with:
That will work but manipulating strings every frame generates garbage for GC and is not recommended. If you have CM 2.6.0 or higher, try adding this script to your FreeLook instead:
using UnityEngine;
using Cinemachine;
public class InputOnMouseDown : MonoBehaviour, AxisState.IInputAxisProvider
{
public string HorizontalInput = "Mouse X";
public string VerticalInput = "Mouse Y";
public float GetAxisValue(int axis)
{
// No input unless right mouse is down
if (!Input.GetMouseButton(1))
return 0;
switch (axis)
{
case 0: return Input.GetAxis(HorizontalInput);
case 1: return Input.GetAxis(VerticalInput);
default: return 0;
}
}
}