I’m working on a iTween-based movement system, and it actually works fairly well. However, there is a problem in that it’s not all that realistic. At current, the character keeps jerking back and forth on it’s “track-rail” style system. It is also animated, and the walking animation does not keep track with it very well. Given the current position, and a known destination, what would be the best way to calculate the amount of time it would take to get to that point? This is my existing code at the moment:
public void Movement()
{
// Select Random point within limits and move to it, then resquence, unless Tween is interrupted, then move towards center //
float RandomPointX = Random.Range (XMinLimit, XMaxLimit);
LastXPoint = CurrentXPoint;
CurrentXPoint = RandomPointX;
Vector3 CurrentPosit = _transform.position;
Vector3 EndPosit = Vector3.zero;
EndPosit.x = RandomPointX;
EndPosit.y = _transform.position.y;
EndPosit.z = 0.0f;
float Magnitude = Vector3.Distance (CurrentPosit, EndPosit);
Debug.Log ("Magnitude of Distance: " + Magnitude);
_animation ["Walk"].speed = (Magnitude / 2) * 4;
Hashtable MoveTable = new Hashtable();
MoveTable.Add ("x", RandomPointX);
MoveTable.Add ("time", Magnitude);
MoveTable.Add ("oncompletetarget", this.gameObject);
MoveTable.Add ("oncomplete", "Movement");
MoveTable.Add ("easetype", iTween.EaseType.linear);
iTween.MoveTo (this.gameObject, MoveTable);
}