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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Сamera rotates jerkily

Discussion in 'Input System' started by zykoff, Aug 9, 2022.

  1. zykoff

    zykoff

    Joined:
    Jul 27, 2022
    Posts:
    3
    Made the rotation of the camera using a swipe. but it does not rotate smoothly, but jerkily. For example, the camera, when rotated diagonally, rotates along the ladder. I don't understand what the problem is.

    Code (CSharp):
    1. using UI_InputSystem.Base;
    2. using UnityEngine;
    3.  
    4. public class CameraMovement : MonoBehaviour
    5. {
    6.     [SerializeField]
    7.     private Transform playerTransform, cameraTranform;
    8.  
    9.     public Vector2 LookAxis;
    10.  
    11.     [SerializeField]
    12.     [Range(25f, 150f)]
    13.     private float mouseSensX = 75f, mouseSensY = 75f;
    14.  
    15.     [SerializeField]
    16.     private float minClampVertical = -60, maxClampHorizontal = 90;
    17.  
    18.     private float verticalRotation = 0;
    19.     private float XValueWithSens => LookAxis.x * Time.deltaTime * mouseSensX;
    20.     private float YValueWithSens => LookAxis.y * Time.deltaTime * mouseSensY;
    21.     private float RotationClamped(float refRotation) => Mathf.Clamp(refRotation, minClampVertical, maxClampHorizontal);
    22.    
    23.     private void FixedUpdate()
    24.     {
    25.         CameraHorizontalMovement();
    26.         CameraVerticalMovement();
    27.     }
    28.  
    29.     private void CameraVerticalMovement()
    30.     {
    31.         if (!cameraTranform) return;
    32.        
    33.         verticalRotation -= YValueWithSens;
    34.         verticalRotation = RotationClamped(verticalRotation);
    35.  
    36.         cameraTranform.localRotation = Quaternion.Euler(verticalRotation, 0f, 0f);
    37.     }
    38.  
    39.     private void CameraHorizontalMovement()
    40.     {
    41.         if (playerTransform == null) return;
    42.  
    43.         playerTransform.Rotate(Vector3.up * XValueWithSens);
    44.     }
    45.  
    46.     public void OverrideLookAt(Transform targetToLook) => cameraTranform.LookAt(targetToLook);
    47. }
    A script hangs on the player to which I attach a panel for swipes

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. public class CameraRotate : MonoBehaviour
    7. {
    8.     public FixedTouchField TouchField;
    9.    
    10.     void Update()
    11.     {
    12.         var fps = GetComponent<CameraMovement>();
    13.      
    14.         fps.LookAxis = TouchField.TouchDist;
    15.     }
    16. }
     
  2. zykoff

    zykoff

    Joined:
    Jul 27, 2022
    Posts:
    3
    I understand. Should have replaced FixedU[date with Update