Hi,
I’m trying to move an object along an arc in 2D and thought the best way was to use Vector3.Slerp and disregard the z. I’m trying to follow the example shown here but it’s not working, the object simply stays stationary in one spot.
Here is my code:
guiBeans = new Dictionary<Vector3, Vector3>();
public void OnGUI()
{
List<Vector3> keys = new List<Vector3>();
foreach (Vector3 key in guiBeans.Keys)
{
keys.Add(key);
}
for (int i = 0; i < keys.Count; i++)
{
Debug.Log("KEY: " + keys[i]);
Debug.Log("VALUE: " + guiBeans[keys[i]]);
GUI.Label(new Rect(guiBeans[keys[i]].x, Screen.height - guiBeans[keys[i]].y, 96, 64), "", guiBean);
Vector3 pos = keys[i];
Vector3 target = new Vector3(Screen.width / 10, Screen.height / 1.2f);
Vector3 centre = pos + target * 0.5f;
centre -= new Vector3(1, 1, 0);
Vector3 posRelCentre = pos - centre;
Vector3 targetRelCentre = target - centre;
guiBeans[keys[i]] = Vector3.Slerp(posRelCentre, targetRelCentre, Time.time);
guiBeans[keys[i]] += centre;
}
keys.Clear();
}
Here is an example of what’s being logged:
KEY: (314.1, 414.6, 141.9)
VALUE: (314.1, 414.6, 141.9)
KEY: (314.1, 414.6, 141.9)
VALUE: (90.0, 502.5, 0.0)
KEY: (314.1, 414.6, 141.9)
VALUE: (90.0, 502.5, 0.0)
KEY: (314.1, 414.6, 141.9)
VALUE: (90.0, 502.5, 0.0)
etc etc…
My understanding is that the key should be the initial position of the object at the beginning of the slerp, and that the value should be the new position of the object each frame as the slerp does its thing. As you can see from the log, the value only changes the first time, then stays the same, which is why my object is stationary. I can see why the value never changes… because its doing the same calculation every frame with the same values. But looking at the example, I can’t see how that is any different.
Anyone able to point out what I’m doing wrong?