Help with player tilt

I’m making a sort of infinite runner/flyer sort of thing at the moment, but I’m having a problem with getting my spaceship thing to tilt. It ‘flies’ (actually, the ground moves, but that’s not important) toward/along the x-axis and I just need it to tilt left a bit when the player is going left and vice-versa.
I found this snippet somewhere, changed it a bit, put it in the update function of ‘Player’ and it’s proved to be half the solution.

float x = Input.GetAxis("Horizontal") * 15.0f;
Vector3 euler = transform.localEulerAngles;
euler.x = Mathf.Lerp(euler.x, x, 2.0f * Time.deltaTime);
transform.localEulerAngles = euler;

This seems to be exactly what I need, and it’s pretty elegant, but it really is only half the solution - literally. When pressing left, it tilts exactly how you would expect. When I attempt to tilt right, it rapidly wobbles somewhere around a rotation of 274 in the x-axis, and flip flops between 0 and 180 degrees in the other 2 axis (according to the inspector).

I’d seriously appreciate some help in fixing this; it’s 1:38 in the morning and it’s keeping me up.

UPDATE: Here’s some screenshots for clarity about what’s going on -
Left:


Right:

And there’s a gif of that here: http://gfycat.com/ImpureBothDinosaur

Hey so I’m super green and might not be of much help. But I just had this problem and seemed like everything was good except for bouncing and titling. For me, I just checked Is kenetic and Use gravity on the rigid body collider and that fixed it.

Thanks for trying, but it didn’t help. In fact, it didn’t even have a rigidbody and adding one and making it kinematic and stuff didn’t make any difference.

It’s not exactly perfect, but I hope it helps

turned off gravity
didn’t enable is kinematic

    public float tilt;
    Rigidbody rb;
    // Use this for initialization
    void Start () {
        rb = GetComponent<Rigidbody>();
    }
  
    // Update is called once per frame
    void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            rb.velocity = Vector3.left * 2f;
            transform.rotation = Quaternion.Euler(0.0f, 0.0f, (transform.position).x * -tilt);
        }

        if (Input.GetKey(KeyCode.D))
        {
            rb.velocity = Vector3.right * 2f;
            transform.rotation = Quaternion.Euler(0.0f, 0.0f, (transform.position).x * -tilt);
        }
}

Thanks for the help, but this appears to cause more problems than it fixes, and I don’t really know how to fix them. It did however help me anyway, as it gave me an idea of how to fix one of my minor niggles with my old code. But, nonetheless, the problem remains. Here is what it looks like now:

        if (Input.GetAxis("Horizontal")>0){
            Vector3 euler = transform.localEulerAngles;
            euler.x = Mathf.Lerp(euler.x, maxTilt, 2.0f * Time.deltaTime);
            transform.localEulerAngles = euler;
        }
        else if (Input.GetAxis("Horizontal")<0 && transform.localEulerAngles.x>1){
            Vector3 euler = transform.localEulerAngles;
            euler.x = Mathf.Lerp(euler.x, 0, 4.0f * Time.deltaTime);
            transform.localEulerAngles = euler;
        }
        else if (Input.GetAxis("Horizontal")<0 && transform.localEulerAngles.x <= 1){
            Vector3 euler = transform.localEulerAngles;
            euler.x = Mathf.Lerp(0, -maxTilt, 2.0f * Time.deltaTime);
            transform.localEulerAngles = euler;
        }

It’s still a work in progress though, because I can’t get past the way once it gets to zero, rather than carry on lerping to -maxTilt, it randomly jumps to ~274 degrees and gets stuck. So, yeah, this still isn’t fixed and I could still really do with some help here.

Well, I got bored and changed the controls to mouse controls (which don’t need lerping), so… While this isn’t exactly solved, I have a workaround.

I played around with a simple flight controller using mouse movement. Maybe you can repurpose the ResetRotation function for what you were looking for.

http://forum.unity3d.com/threads/arcade-flight-controller.298182/#post-1964018