- Home /
Question by
abelegu2 · Apr 15, 2015 at 01:07 PM ·
javascriptrotateitweenitweenpathputonpath
Orienting to path for iTween.PutOnPath function
I'm using iTween's PutOnPath function to move an object down a curved iTweenPath. I basically want the "OrientToPath" functionality, but PutOnPath doesn't accept any Hash parameters...
I've tried setting iTween.LookTo to the PointOnPath right ahead of the current percentage, but it doesn't work at all... I'm all out of ideas right now. How to make it so that it rotates to face the direction it is travelling?
This is my code so far (I referred to this answer to figure out how to manipulate speed on a running iTween), and it currently doesn't do anything except move the character down the path based on the speed given.
var PathOnePercent : float = Vector3.Distance(iTween.PointOnPath(iTweenPath.GetPath("LevelPath_1"), percentage), iTween.PointOnPath(iTweenPath.GetPath("LevelPath_1"), percentage + 0.1f));
var RealOnePercent : float = iTween.PathLength(iTweenPath.GetPath("LevelPath_1")) * 0.1f;
var Distortion : float = RealOnePercent / PathOnePercent;
var RealPercentToMove : float = (currentSpeed * Time.deltaTime) / iTween.PathLength(iTweenPath.GetPath("LevelPath_1"));
percentage = (RealPercentToMove * Distortion) + percentage;
iTween.PutOnPath(gameObject, iTweenPath.GetPath("LevelPath_1"), percentage);
Any ideas how to make it rotate appropriately to its direction?
Thanks in advance!
Comment