# Making a forked path with iTween

I’m been having trouble creating a game with a set node path. The game I’m making places the player character on a strict path with nodes. For example, if the player presses a button to go left, she will move to the closest left node on the map; otherwise the player will get a warning that the player cannot move in that direction. The same factors for when the player want to go to the right, up or down.

I’ve been trying to create a forked path with iTween using the iTweenPath script, but I have run into some issues with the system. For example, for a path with 5 nodes (numbered 0 - 4), if node 2 could branch off to either node 3 or node 4, I cannot determine where the player should go to. One solution I have thought of was to create a new path for each decision, but then how would I define when the player is able to travel to a branch in the fork (i.e. from node 2 to either node 3 or 4)?

One step in the right direction would be the ability to place the player on a specific node on the path, but I’m not sure if this is possible to perform with iTween. I read another topic discussing placing an object from node to node, but I was unable to understand it.

Any suggestions for creating a forked path using iTween would be much appreciated.

So, given the example described in
this picture, would the function to go
to node 3 from 2 be 2.3 and the
function to go to node 4 be 2.4?

It depends on which solution you go with. Say you want to branch at any node (the second solution I presented). And say the two paths end at the edge of the drawing (at nodes 3 and 4). You would need two paths. One would be (0, 1, 2, 3). The second path would have (2, 4). If I remember correctly, with iTween, paths can be built out of either Vector3 or Transform, which gives you some flexibility on how you build your paths.

So the first path (0,1,2,3) has four nodes and three path segments. That means that nodes will be at these fractions:

``````0 - 0.0
1 - 0.333
2 - 0.666
3 - 1.000
``````

That is, for any path, the fraction along that path can be calculated by:

``````var fraction = 1.0 / (numberOfNodes - 1) * NodeIndex;
``````

You are going to have to build some other data structure to tell that at node 2 of path #1, there is a branch to path #2. If the user selects path #2, when you get at/near node #2 (fraction .6666), you then switch to using path #2 for your movement, and the fraction along that path goes to back 0.0 since you are just starting that new path.

The first solutions (branching only at the end) is similar. The difference is that you end up with three paths. (0,1,2), (2, 3) and (2, 4). This solution means that you store one array of possible new paths at the end of any give path. So you only branch at when you end up at the end of a path. That means no node fraction calculations as the cost of generating more paths.