I have to move object from -10 to +10 x position. But I want to start my object from zero x.point to move, how can I start my lerp at the middle position?
Edit2: Object should start at x = 0 position and move to +10 x position and go to -10 x position and again +10 x, -10 x like a loop.
Vector3 pos1, pos2, pos0, pos3;
void Start()
{
pos0 = transform.position;
pos1 = pos0 + new Vector3(10, 0, 0);
pos2 = pos0 - new Vector3(10, 0, 0);
pos3 = pos1;
}
float time = 0.5f;
void FixedUpdate()
{
time += Mathf.PingPong(Time.time * 0.5f, 1.0f);
transform.position = Vector3.Lerp(pos2, pos1, time);
}