- Home /
iTween MoveTo + Rotation?
Hello everyone.
I'm using iTween's MoveTo to move my gameobject along a path and everything works fine.
My problem is, the rotation of the gameobject stays the same while he is moving along the path.
I want him to rotate in the direction of the path.
This is my line of code:
iTween.MoveTo(gameobject, iTween.Hash("path", iTweenPath.GetPath("MyPath"), "time", 500));
Thanks!
Answer by aliakbo · Jan 20, 2013 at 07:17 PM
As the iTween documentation shows-
You can use the "orienttopath" property to orient to its direction of travel and the "lookahead" property to influence how strict "orienttopath" is and how much the object will anticipate each curve.
"orienttopath" is a boolean so you should set it to true, "lookahead" should be set to a value between 0 and 1 depending on how you want your gameobject to react.
Your final code would look something like this-
iTween.MoveTo(gameobject, iTween.Hash("path", iTweenPath.GetPath("MyPath"),
"orienttopath", true, "lookahead", .5f, "time", 500));
I added the values you said but it still wont rotate. By looking at the rotation of the object while its moving, I do see it change but very very little, so its hardly noticeable. I even triad it with lookahead set to 1 but still nothing.
Apparently I somehow missed "looktime" in my answer above, set "looktime" to a small number and see how it works out.
I added the "looktime" with a value of 0.01 Now the object is facing a totally different direction but still not rotating along the path.
Answer by shra12ddha · Sep 05, 2015 at 03:14 PM
You can use iTween : iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("New Path 1"), "time", 50, "orienttopath", true));
By this line of code your object will follow the path and will run along that path only.
Hi,
I am creating a 2d game, in which a sprite is following some random path. I have successfully completed the following thing but my gameobject is not rotating according to the path. I am using itweenpath. Any help?
Answer by saliakbari6603 · Dec 09, 2018 at 10:34 AM
if you use 2D project: replace itween class with iTween.txt in attach. and change or add :
void Awake()
{
iTween.dimensionMode = iTween.DimensionMode.mode2D;
}
enjoy :)
@saliakbari6603 iTween.dimensionMode doesn't exist anymore. Any idea how to replace it? many thx.
Your answer
Follow this Question
Related Questions
iTweens MoveTo and "path" property 7 Answers
itween path restrict rotation on TWO axis 0 Answers
iTween Camera Jitter while moving on path 2 Answers