I just tested your code and for me it works fine. This is what I ended up using
public class Test : MonoBehaviour
{
Vector2 a = new Vector2(0, 0);
Vector2 b = new Vector2(0, 5);
float movementSpeed = 2f;
private void Update()
{
float move = Mathf.PingPong(Time.time * movementSpeed, 1);
transform.position = Vector2.Lerp(a, b, move);
}
}
Are you sure its the code itself that is wrong? Could it be something else in the game engine that isnt set up properly, for example, have you attached this script as a component to the object you want to move? Are there any other scripts that could affect this objects position? I dont think the issue is in this piece of code, the problem comes from somewhere else.