iTween 2 patrol movement problem

So I want a gameobject (a cude for now) to walk from point A to B then back to A and so forth as a guard would do if he had to walk a perimeter.
I saw the iTween script on here and it seems to make the moving animations allot easier but the only free tutorials I could find on the internet are for version 1 and not the new version 2.
The reason I can’t buy a tutorial is because this a school project and we aren’t allowed to buy scripts as it would be cheating because we have to program everything ourselves.

public Transform patrolPoint1;//left point move to right
public Transform patrolPoint2;//right point move to left
public float time;

// Use this for initialization
void Start () {
	roll("right");
}
	
private void roll(string direction){
	switch(direction){
		case "right":
		//iTween.RotateBy(gameObject,patrolPoint2.transform.position, 1);
		Hashtable moveRightHt = new Hashtable();
		moveRightHt.Add("target", "patrolPoint1.transform.position");
		moveRightHt.Add("onComplete", "roll");
		moveRightHt.Add("onCompleteParams", "left");
		moveRightHt.Add("time", time);
		iTween.MoveTo(gameObject, moveRightHt);
		break;
		
		case "left":
		//iTween.RotateBy(gameObject, patrolPoint1.transform.position, 1);
		Hashtable moveLeftHt = new Hashtable();
		moveLeftHt.Add("target", "patrolPoint2.transform.position");
		moveLeftHt.Add("onComplete", "roll");
		moveLeftHt.Add("onCompleteParams", "right");
		moveLeftHt.Add("time", time);
		iTween.MoveTo(gameObject, moveLeftHt);
		break;
	}
}

I used the hashtables because the {“x”:1.7, “time”:2} kind of solution from the tutorials kept giving unity errors on the {}'s.
when I run this script I keep getting an error

Can anybody please tell me what I am doing wrong?

kristalghost

First, the issue you state that you are having that required you to use hashtables is because you can’t create hashtables in C# that way (only in JS). You can also try using iTween’s Hash() method to save a little on typing.

Second does the code I wrote here help? http://answers.unity3d.com/questions/20818/simulating-rotation-over-edge-with-itween

how do i use the hash() method in C#?
and the code you wrote there keeps giving me errors because of the {} in the iTween statements

Ex: iTween.MoveUpdate(gameObject,iTween.Hash(“path”, posList));

Just put the arguments in alternating pairs ex. (“time”,1.0f, “path”, vectorList, “lookTime”, 1.0f );

theres an example on the documentation if you’re using visual c# express, or in the iTween documentation’s site.

AWESOME! that should help out allot!
Thank you

Oke so now I have a new problem, I got the MoveTo to work but when it moves to my point it moves very fast at the beginning and then slow down to a crawl a little before the target.
It travels about 85% of the distance in about 50% of the time and then 15% in 50% of the time so it appears to be standing still at the end.
Is there a way to make it move to a position at a consistent speed?

thanks in advance,
Kristalghost

Take a look at the “easttype” parameter :wink:

NICE! You’re iTween script is very impressive once you understand how to use it.
thanks for the help

Just wanted to add for those just starting out with iTween - the following “helper” class makes rapidly learning/developing with it even easier:

http://blog.almostlogical.com/2010/09/13/itween-parameter-code-hinting/