- Home /
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.
As a design question, this issues is better asked at Unity Forums. The one specific question you ask is how to place the player at a specific node. I'm assu$$anonymous$$g you are moving your player through iTween.PointOnPath() and/or iTween.PutOnPath(). They both take a fraction. That fraction is evenly divided between the nodes in your path.
For example, let's say that the path has 11 nodes resulting in 10 path segments. If the fraction is between 0.0 and 0.1, then it is between nodes 0 and 1. If the fraction is 0.3, then it will be at the zero-based node 3.
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?
Answer by robertbu · May 06, 2014 at 07:23 PM
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.
Your answer
Follow this Question
Related Questions
iTween MoveTo "Convoy" 0 Answers
changing itween moveTo speed param. 0 Answers
3D Text to follow a path; iTween 0 Answers
draw a path in game with touch and move player on it 0 Answers
Scale an iTweenPath 0 Answers