Hello, Im making a simple endless run with a ball who moves in “rails” with finger swipes. My problem is that after i made the code for swipes the ball is stuck in the beginning position.
public float playerSpeed;
public float diagonalSpeed;
public Vector3 destination;
void Start()
{
destination = transform.position;
}
void Update()
{
GetComponent<Rigidbody>().velocity = Vector3.forward * playerSpeed * Time.deltaTime;
transform.position = Vector3.Lerp(transform.position, destination, diagonalSpeed *
Time.deltaTime);
if (SwipeManager.IsSwipingLeft())
{
destination = new Vector3(transform.position.x - 4f,transform.position.y, transform.position.z);
}
if (SwipeManager.IsSwipingRight())
{
destination = new Vector3(transform.position.x + 4f, transform.position.y,
transform.position.z);
}
}
I think its because i call the vector3.Lerp every frame but i dont know how to fix this. Thank you very much for the help.