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
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.
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?