private float getTimeToNextWaypoint(RailWaypoint currentWaypoint, RailWaypoint nextWaypoint) { switch (nextWaypoint.type) { case RailWaypoint.Type.TIME: return nextWaypoint.value; case RailWaypoint.Type.VELOCITY: return (nextWaypoint.transform.position - currentWaypoint.transform.position).magnitude / nextWaypoint.value; default: return 0f; } }
private Vector3 interpolatePosition(RailWaypoint currentWaypoint, RailWaypoint nextWaypoint, float deltaTime, float travelTime) { //Have a look at this //http://answers.unity3d.com/questions/12689/moving-an-object-along-a-bezier-curve.html if (nextWaypoint == null) return currentWaypoint.transform.position; if (travelTime <= 0f) return nextWaypoint.transform.position; return Vector3.Lerp(currentWaypoint.transform.position, nextWaypoint.transform.position, deltaTime / travelTime); }