I found this script on another UnityAnswer.
It is a script that let an object (where this script is attached to). Move in between point A and B. In this script defined as pos1 and pos2.
But there is something about this script that bothers me, When changing the variable speed on runtime. To like 2f; The object will re-position itself to a new location. It doesn’t just only change the speed but it also changes the position of the gameObject.
My question : Why does it do this.
public class Example3 : MonoBehaviour {
private Vector3 pos1 = new Vector3(-3,3,0);
private Vector3 pos2 = new Vector3(3,3,0);
public float speed = 1.0f;
void Update() {
transform.position = Vector3.Lerp (pos1, pos2, (Mathf.Sin(speed * Time.time) + 1.0f) / 2.0f);
}
}