Using iTween to move a gameobject from node to node

Hello all,

I am using the iTween path for a level select menu. I have the path nodes set up to the location of the level buttons. I have a user icon that I want to move from node to node when the level button is pressed. I’ve tried using the documentation and other forum posts but I wasn’t getting anywhere fast! So, my user icon starts on level 1. When I click level 6 I want the user icon to travel the path of the iTweenPath until it gets to the sixth node(same location as the level 6 button). How can I accomplish that? I would post my code but its pointless b/c its very broken. I came close to what I want with this code but the user icon gameobject displayed very wierd behavior(usericon transporting around the scene).

Before trying the .moveto() method I was using the .putonpath() which just teleported the usericon to the button location. It was great minus the fact it didn’t walk there. Any suggestions?? If you need code I’ll upload it but like I said before it really doesn’t work at all.

Also, I got the moveto to work but the usericon wouldn’t move along the iTweenPath it would just pan from button location to button location

Update 1:
Ok, so I got close to what I want.

iTween.MoveTo(userIcon.gameObject, iTween.Hash("position", new Vector3(worldPath.nodes[moveDestination].x, worldPath.nodes[moveDestination].y, 0.0f), "path", iTweenPath.GetPath("World0Path"), "movetopath", false, "time", 5.0f, "looptype", "pingPong"));

This line of code moves the usericon along the path but it always moves it to the last node in the iTweenPath. I thought I could use the position parameter to be the end position but clearly I was wrong.

Update 2:
The iTween documentation says the position arg is supposed to be the “for a point in space the GameObject will animate to.” With my line of code(still the one from above) no matter what I set the position arg to be it still always ends at the end of the iTweenPath

The key to this is to give it the correct path.

Right now, you’re always giving it the same path, right? (iTweenPath.GetPath(“World0Path”)) Instead, give it only the nodes it needs.

var nodes: Vector3[]; //master list of all nodes, in order
var path: Vector3[]; //the path that you will use for iTween

function ChoosePath (pathStart: int, pathEnd: int) {
	path = new Vector3[Mathf.Abs(pathEnd-pathStart)+1];
	//make the path move in the opposite direction is pathStart is greater than pathEnd
	var sign: int; //negative or positive value
	if (pathStart > pathEnd) {
		sign = -1;
	} else {
		sign = 1;
	//assign values from nodes to path
	for (var i:int; i<path.length; i++) {
		path _= nodes[pathStart+(sign*i)];_
  • }*
    This will assign a path based on the start and end points you choose. Use that value with your iTween.MoveTo.
    ChoosePath(2, 5); //move from element 2 in nodes to element 5 in nodes (from nodes[2] to nodes[5])