I wanted my object(ring) to move from left to right. but the code we have here seems to work but the movement is too fast. what else can we do to make it move from left to right with not too fast not too slow movement.
using UnityEngine;
using System.Collections;
public class Accelo : MonoBehaviour {
public Transform carTransform;
private float[] pos = new float[] {-70.0f, 0.0f, 70.0f};
private int speed = 2;
// Use this for initialization
void Start () {
}
void Update() {
Vector2 dir = Vector2.zero;
dir.x = Input.acceleration.x;
int z = 5;
int y = 10;
if(y>z){
rigidbody.AddForce(Vector3.forward*2);
}
if(dir.x < -0.21)
{
float x = Mathf.Lerp(carTransform.position.x,pos[0],Time.deltaTime);
carTransform.position = new Vector3(x, 0, 0);
}
if(dir.x > 0.21)
{
//TurnWheelsRight();
float x = Mathf.Lerp(carTransform.position.x,pos[2],Time.deltaTime);
carTransform.position = new Vector3(x, 0, 0);
}
}
}
Thank you