iTween Script Paths Speed change over time

Is there a way to change the iTween.MoveTo speed over time while the iTween is already running , or is there another handy way to do this?

The project: move a player along a generated path but let the user control the speed of the movement.

If you have another idea how to do this pleas let me hear it.

I am looking for the same answer… did you happen to find it? Do you mind sharing it?

I found out the answer, and just would like to share it (remembering off the top of my head)

var speed : float = 1.0;
var distance : float = 0.0;
var thePath : Vector3[];
var pathLength : float;

function Start()
{
    thePath = iTweenPath.GetPath("path_name");
    pathLength = iTween.PathLength(thePath);
}

function Update()
{
    distance += speed * Time.deltaTime;
    var perc : float = distance / pathLength;
    iTween.PutOnPath(gameObject, thePath, perc);
}

Hope it helps someone else out there

1 Like

I’m not sure how the guy above’s code works but this is the easiest way that I have found how to do this:

using UnityEngine;
using System.Collections;

public class SpeedPath : MonoBehaviour {

	void Start () {
	StartCoroutine(FirstRun());	
	}

	
	void SpeedItUp()
	{
		//if reference is another object change this.game to something else
		iTween ITSP = (iTween)this.gameObject.GetComponent(typeof(iTween));
		//keep this number low as possible or it will jump (go faster by changing time below)
		ITSP.time = ITSP.time - 0.01f;
		StartCoroutine(TimedSpeedUp());
		
	}
	
	IEnumerator TimedSpeedUp()
	{
		//change the wait time here
		yield return new WaitForSeconds(0.5f);
		SpeedItUp();
		
	}
	
	IEnumerator FirstRun()
	{
		//wait one second before start for Itween to instantiate on object
		yield return new WaitForSeconds(1);
		SpeedItUp();
		
	}
}