- Home /
Is it possible to generate a Path from iTween?
I'm curious if it is possible to generate a Vector3[] of path points from an iTween without having to actually run the tween in game to first "gather" the points"?
For example, if I have a gameObject animate and rotate from one position to another, can I get a path of points in Vector3[] format (positional and rotational) that would represent that objects path through space?
Answer by robertbu · Jul 10, 2013 at 02:43 AM
It is not possible to gather the position/rotation points without running the iTween. Some things you can do:
You can run the iTween without the game object visible, and possibility at a much higher rate of speed and collect the data.
For simple movements (linear movement without easing, linear rotation without easing), writing code to capture a similar path/rotation is not too difficult.
It is possible to run the game in the editor and capture the information, copy the game object at the end of the run (while the game is still running), and then past the game object after stopping the editor. If the array is public, your pasted object will have the captured data.
You can capture the data during an editor run and write it out to somewhere permanent. Then use the captured data.
Thanks Robertbu. That's what I figured. I ended up doing the linear movement route without easing and it was pretty easy to capture the points and I wanted something easy to use ins$$anonymous$$d of having to copy/paste data.
Answer by justinl · Jul 10, 2013 at 03:01 AM
For reference, here is how to capture a basic linear path between 2 objects and store the position and rotation in separate Vector3[]'s.
int pathResolution = 100; //how many points you want in your path
Vector3[] pathPosition = new Vector3[pathResolution];
Vector3[] pathRotation = new Vector3[pathResolution];
float distanceBetween = Vector3.Distance(startPosition, endPosition);
Vector3 deltaPositionVector = endPosition - startPosition;
Vector3 deltaRotationVector = endRotation - startRotation;
//generate path points
for(int i = 0; i < pathResolution; i++){
pathPosition[i] = startPosition + (deltaPositionVector.normalized * (distanceBetween * i/pathResolution));
pathRotation[i] = startRotation + (deltaRotationVector * i/pathResolution);
}