- Home /
iTween PointOnPath percentage
I have a player running on a path created with iTween.PointOnPath().
I'm instantiating new paths for the player to follow when he runs over a trigger. The problem I'm having is when I add new Transforms to the array it skips several sets of nodes, and continues on it's way. I see the pathPercentage variable increments normally, based off speed and deltaTime. Am I not scaling the percentage by the appropriate factor?
I'm sure my problem lies in the percentage used / Player Positioning, but I'm not seeing it.
float pathPercent = pathPosition % 1;
Vector3 coordinateOnPath = iTween.PointOnPath(_pathNodesScript.PathNodesToFollow, pathPercent);
Thanks Jon
Not sure what you intend to do to pathPosition, but val % 1 is the same as val
Answer by JonD · Jan 14, 2011 at 03:57 PM
I fixed my problem, I'll post it for future questions.
I'm adding Transforms to an array, but I'm not removing them. This way I get a consistent percentage along the entire array.
pathPosition += Time.deltaTime * .2f;
pathPercent = (pathPosition / _pathNodesScript.PathNodesToFollow.Length) * PlayerSpeed;
Answer by JonD · Mar 26, 2011 at 03:56 PM
Take a look at the method signatures for PointOnPath
PointOnPath(Transform[] path, float percent)
PointOnPath(Vector3[] path, float percent)
Write it in the form of whatever iTweenPath.GetPath returns, then the percentage.
Then I would compare that point to the point of the cube
Unless I'm missing something, that should do it. Remember, Time.time is the time this frame has started. This is the time in seconds since the start of the game.
Jon
Your answer
![](https://koobas.hobune.stream/wayback/20220613095341im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to control a game object's movement in iTween 1 Answer
iTween : Move Just a Small Portion of a Path? 2 Answers
how to loop an animation 2 Answers
iTween PointOnPath 2 Answers