This car is a rigidbody2D object that is constantly going Vector3.up * 10 while it does not collide into anything on the 2D plane. While I can move the car left and right, it does not translate smoothly. My objective is to be able to move the car left and right smoothly, but the fact that the car is constantly moving and that I can’t just lerp the X-position of the car is causing me a headache.
void Update () {
if (Input.GetKeyDown("left"))
{
if (transform.position.x > -1)
{
//Vector3 targetPos = transform.position;
//targetPos.x -= 1.25f;
MoveLeft ();
}
}
if (Input.GetKeyDown("right"))
{
if (transform.position.x < 1.5)
{
MoveRight();
}
}
}
void MoveLeft() {
Vector3 targetPos = transform.position;
targetPos.x -= 1.25f;
transform.position = Vector3.Lerp(transform.position, targetPos, 1f);
}