So I have two cubes, (1,0,0) and (-1,0,0). If I use Vector3.Slerp() on these two cubes. This works fine.
However if the cubes are away from the origin, lets say the new positions are (3,0,0) and (1,0,0). Slerp no longer behaves as I think it should do.
So two questions. How do I get what I want done? And whats really going on here ?
I’ve posted my working code below. Feel free to comment, I’m super new to unity c#.
public float timeToComplete;
float startTime;
Vector3 startPosition, endPosition;
public GameObject go1;
public GameObject go2;
Vector3 po1, po2;
GameObject go;
void Start(){
startTime = Time.time;
po1 = go1.transform.position;
po2 = go2.transform.position;
}
// Update is called once per frame
void Update () {
var d = (Time.time - startTime) / timeToComplete;
go1.transform.position = Vector3.Slerp (po1, po2, d);
go2.transform.position = Vector3.Slerp (po2, po1, d);
var tep2 = go2.transform.position;
tep2.z *= -1;
go2.transform.position = tep2;
}