Hey Guys, I have tried to cobble together the code bits shared on another thread on adding mouse wheel zooming with FreeLook Camera rig. In addition, my rotation only works when the mouse button is pressed.
Everything works for the most part, however I notice when I use the mouse wheel for zooming, it seems to be sluggish when changing directions. To be more specific, if I advance the wheel one notch/click at a time, when I go the other direction, the first notch/click still goes in the old direction before the 2nd notch/click works properly. It’s as if the Z Axis Value being used is one frame behind or something when updating it’s axis direction. When running you can see the Value rising with each mouse wheel rotation and the instant you reverse mouse wheel rotation, the value continues to rise one more time before it begins to actually reverse the value and decrease. Hopefully this makes sense. All in all, it just feels sloppy and slightly confusing when users go from zooming in to out or vice versa.
Any advice appreciated, I’ve been trying to figure it out for a few days now and it all looks the same at this point.
I believe these are the relevant code bits I’m using.
private void Start()
{
CinemachineCore.GetInputAxis = GetInputAxisCustom;
}
void Awake()
{
freelook = GetComponentInChildren<CinemachineFreeLook>();
}
void Update()
{
_freeLookActive = Input.GetMouseButton(0);
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
MouseWheelZoomCamera();
}
}
private float GetInputAxisCustom(string axisName)
{
if (_freeLookActive)
{
switch (axisName)
{
case "Mouse X":
return Input.GetAxis("Mouse X");
case "Mouse Y":
return Input.GetAxis("Mouse Y");
case "Mouse ScrollWheel":
return Input.GetAxis("Mouse ScrollWheel");
default:
Debug.Log("Axis returned 0");
break;
}
}
if (axisName == "Mouse ScrollWheel")
{
return Input.GetAxis("Mouse ScrollWheel");
}
return 0;
}
public void MouseWheelZoomCamera()
{
if (originalOrbits != null)
{
zAxis.Update(Time.deltaTime);
float scale = Mathf.Lerp(minScale, maxScale, zAxis.Value);
for (int i = 0; i < originalOrbits.Length; i++)
{
freelook.m_Orbits[i].m_Height = originalOrbits[i].m_Height * scale;
freelook.m_Orbits[i].m_Radius = originalOrbits[i].m_Radius * scale;
}
}
}