- Home /
 
 
               Question by 
               OreganoDev · Jul 31, 2020 at 04:40 AM · 
                2d2d game2d-physics2d sprites2d-gameplay  
              
 
              Why Is there A slight jitteryness on player movement and camera?
Hey Everyone, so I spent a day now trying to fix this problem of mine. Its where the player and camera have some jittery movement. I am very new to unity and was wondering how I could fix this. The movement is a Brackeys tutorial along with the camera. The camera also has pixel perfect movement except pixel snapping is off. Any help would be amazing. Thanks Everyone. Here is the Movement code:
 public class PlayerMovement : MonoBehaviour
 {
     public float MoveSpeed = 5f;
     Vector2 Velocity;
     Vector2 mousePos;
     
     public Rigidbody2D rigidbody;
 
     //Camera Movement
     public Camera cam;
 
     public GameObject firePoint;
     // Update is called once per frame
     void Update()
     {
         Velocity.y = Input.GetAxisRaw("Vertical");
         Velocity.x = Input.GetAxisRaw("Horizontal");
 
         mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
 
         
         Vector2 firePointDir = mousePos - rigidbody.position;
         float angle = Mathf.Atan2(firePointDir.y, firePointDir.x) * Mathf.Rad2Deg - 90f;
         firePoint.GetComponent<Rigidbody2D>().rotation = angle;
         firePoint.GetComponent<Transform>().position = transform.position;
 
         
     }
     
     void FixedUpdate()
     {
         rigidbody.MovePosition(rigidbody.position + Velocity * MoveSpeed * Time.fixedDeltaTime);
     }
 
 }
 
               Here is the Camera Code:
 public class CameraMovement : MonoBehaviour
 {
     public Transform target;
     public Vector3 offset;
     public float smoothSpeed = 0.125f;
     void FixedUpdate() {
         if(transform.position != target.position + offset) {
             transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothSpeed);
         }
     }
 }
 
 
              
               Comment
              
 
               
              Your answer