Why is it that every time I click on the touchpad, the cinemachine camera turns to the right and this only happens when the character is running, but if the character is standing still, this does not happen?
public Image imgPanel;
[SerializeField] CinemachineFreeLook camFreeLook;
string strMouseX = "Mouse X", strMouseY = "Mouse Y";
bool isDragging = false;
void Start()
{
imgPanel = GetComponent<Image>();
}
public void OnDrag(PointerEventData eventData)
{
if (isDragging && RectTransformUtility.ScreenPointToWorldPointInRectangle(
imgPanel.rectTransform, eventData.position,
eventData.enterEventCamera, out Vector3 posOut))
{
float deltaX = eventData.delta.x / Screen.width;
float deltaY = eventData.delta.y / Screen.height;
camFreeLook.m_XAxis.m_InputAxisValue = deltaX;
camFreeLook.m_YAxis.m_InputAxisValue = deltaY;
}
}
public void OnPointerDown(PointerEventData eventData)
{
isDragging = true;
camFreeLook.m_XAxis.m_InputAxisName = strMouseX;
camFreeLook.m_YAxis.m_InputAxisName = strMouseY;
}
public void OnPointerUp(PointerEventData eventData)
{
isDragging = false;
camFreeLook.m_XAxis.m_InputAxisName = null;
camFreeLook.m_YAxis.m_InputAxisName = null;
camFreeLook.m_XAxis.m_InputAxisValue = 0;
camFreeLook.m_YAxis.m_InputAxisValue = 0;
}