Why is this code glitching?

Whenever I use this code, the player character is always glitching, by teleporting to the left and right of the screen extremely fast. Can anybody explain what i’m doing wrong?

using UnityEngine;
using System.Collections;
using System;

[System.Serializable]
public class Boundary
{
     public float xMin, xMax, zMin, zMax;
//xMin = 4, xMax = -4, zMin = 2.39, and zMax = 3.84
}

public class PlayerContoller : MonoBehaviour
{
     public float speed;
     public float tilt;
     public Boundary boundary;
     public Rigidbody rb;

     void Start()
     {
           rb = GetComponent<Rigidbody>();
     }

     void FixedUpdate()
     {
           float moveHorizontal = Input.GetAxis("Horizontal");
           float moveVertical = Input.GetAxis("Vertical");
           
            Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
            rb.velocity = movement * speed;

            rb.position = new Vector3
               (
                     Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
                   0.0f
           Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
           );

           rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
     }
}

Speed = 5

Your xMin and xMax values are the wrong way around.

//xMin = 4, xMax = -4

Hi,

It’s

rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);

not

 rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt)'