help with object move with rotation by touch

hello. iam kind new here ^^
iam working on new unity project which i want to move my player object right and left based on two gui textures on right and left of the screen,
when press right and left it goes to rotation z like 5 and -5. without smoothly rotate.

I’ts moving right and left, but it’s not smoothly rotation when moving…
how to fix the rotation and make it smooth?
sorry for my bad English ^^

so this is my script without gui textures…

void FixedUpdate ()
 {

float LeftRight = 0;

if(Input.touchCount > 0){

// touch x position is bigger than half of the screen, moving right
if(Input.GetTouch(0).position.x > Screen.width / 2)
LeftRight = 1f;
            
// touch x position is smaller than half of the screen, moving left
else if(Input.GetTouch(0).position.x < Screen.width / 2)
LeftRight = -1f;
 }

Vector3 movement = new Vector3 (LeftRight, 0.0f, 0.0f);
      

Rigidbody.velocity = movement * speed;
      
Rigidbody.position = new Vector3   (Mathf.Clamp(Rigidbody.position.x, xMin, xMax),0.0f,
Mathf.Clamp(Rigidbody.position.z, zMin, zMax));
      
 Rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, Rigidbody.velocity.x * -tilt);
       }

sorry i posted two threads…

The way I do touch is buttons its simple,

public gameobject Object; 
void buttonturned(){

transform.translation(Object.Vector3, left) * time.deltatime * 1; 

}

hey, thank you
but it didn’t helped me, my controls is working in my script, What i want to fix is my rotation because its not smoothly rotate. when i move right for example, the number of “Z” rotation changed from 0 to 5 … which makes it not smooth…
btw, is your code is like this?

public Gameobject Object;
void buttonturned(){
Object.transform.Translate(Vector3.left * time.deltatime * 1);
}

I think I didn’t code it right but you can look it up. Also, it dose that because the origin in off center. its 99.9% impossible to get the origin in the exact middle. I’m guessing its in a parent so, look at parent origin. Move the objects in the parent closer to the origin. Closer the better. :smile:

Thank you ! But I’ve managed to fix it ^^
Here is my final code script

using UnityEngine;
using System.Collections;

[System.Serializable]



public class PlayerMovementLeft : MonoBehaviour {
  
  
    private float speed = 20f;
    public float xMin, xMax, zMin, zMax;
    public float LeftRight;
  


    void FixedUpdate ()
    {
        float LeftRight = 0;
        if(Input.touchCount > 0)
        {
            // touch x position is bigger than half of the screen, moving right
            if(Input.GetTouch(0).position.x > Screen.width / 2)
            {
                rotateRight();
                LeftRight = 1f;
            }

            // touch x position is smaller than half of the screen, moving left
            else if(Input.GetTouch(0).position.x < Screen.width / 2)
            {
                rotateLeft();
                LeftRight = -1f;
            }
        }

        rotateOrignel ();
        Vector3 movement = new Vector3 (LeftRight, 0.0f, 0.0f);
        GetComponent<Rigidbody>().velocity = movement * speed;

        GetComponent<Rigidbody>().position = new Vector3(Mathf.Clamp (GetComponent<Rigidbody>().position.x, xMin, xMax), 0.0f, Mathf.Clamp (GetComponent<Rigidbody>().position.z, zMin, zMax));

    }
  

    void rotateRight()
    {
        Quaternion newRotation = Quaternion.AngleAxis (90, Vector3.back);
        transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, 0.03f * Time.timeScale);
    }

    void rotateLeft()
    {
        Quaternion newRotation = Quaternion.AngleAxis (90, Vector3.forward);
        transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, 0.03f * Time.timeScale);
    }

    void rotateOrignel()
    {
        Quaternion newRotation = Quaternion.AngleAxis (0, Vector3.zero);
        transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, 0.3f * Time.timeScale );
    }
  
}