- Home /
[SCREENSHOTS] itween Path, orientToPath and gameObject rotation, 2D game
Hello community
I have a plane, and a texture attached to it ( Spaceship ). This spaceship has a "direction". I have built a path, via Itween Path through the Editor and applied Itween.MoveTo function at Start() :
void Start() {
iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("spaceshipPath"), "axis", "z", "time", 20, "orienttopath", true));
}
My spaceship follow the path properly. However, I thought that with orienttopath=true parameter, it would rotate automatically according to the curve, but it does not rotate at all.
I have tried to set the axis to x or y, but i have a weird behavior, rotating the spaceship to any direction.
In my point of view, the rotation axis should be 'x' though. I have also played with looktime and lookahead parameter, but no luck.
Do you think it is feasible to achieve what i want using only itween.MoveTo in the Start() ?
I guess it would be possible to play around Itween.MoveUpdate + LookAtTarget in the Update() function. LookAtTarget would be the direction vector, calculated in the FixedUpdate() ( target = new position - old position ) but not sure either.
Spaceship starts from here :
Then, it gets here :
I would expect to have something like :
The spaceship is just a plane with a texture using transparent shader attached to it.
Any help would be greatly appreciated
Thanks
Florent
I meet the question as valdelievre,can any one show the project with simple example,thanks great.
Answer by BLarentis · Aug 23, 2012 at 03:33 PM
Ok, got this. What you will have to do is 3 things:
1- Remove the Hash item "axis","z".
2 - Create an empty Game Object and rotate him, so his Axis Z, will be the front of the space ship. As an example, I created a plane with an arrow texture. For it to become with the arrow up, I needed to rotate it 90 in X, and 180 in Y. The empty Game Object I rotate it to 270 in X and 270 in Y. S o the blue arrow(Z axis) of the empty Game Object faced the same direction of my plane arrow.
3- Put your space ship as a child of this empty Game Object. And put the spaceship position on 0,0,0 after. So the center of the spaceship will become the position of his parent, the empty Game Object.
Take care!
Thank you so much, after some tweeking, it works as expected. Thank you guys !
valdelievre, can you share you tweeks/)solution? thanks.
I'm having the same issue. I'm trying to have a 2d ship follow the path while only rotating on one axis. So the ship points the direction is should go but not twist about like a ballerina on mescaline. The problem is, I can't find any answers with the exception of this one, though I can't for the life of figure out how this can fix the issue.
From my understanding, the instructions here say to place my ship at 0,0,0, then create an empty GameObject with the same orientation and position as my ship, then place the ship within the GameObject, and move my ship that it is looking toward the empty gameobject's center. This then forces the ship to lock at my desired orientation.
$$anonymous$$aybe I'm not understanding what is being written in step 2, it's hard to visualize. I just can't seem to work out how the parent object's existence can affect the path code in anyway. I'd like to see valdelievre's solution. Or maybe see a visual step by step, if possible.
Answer by brunopava · Aug 23, 2012 at 03:55 PM
You should try to put your space ship inside a empty game object with it's Z axis facing towards were you want to go(in that case, right). Then you use iTween path on the new object.
Let me know if it works.
Answer by Iceo MK · Feb 02, 2014 at 12:53 PM
Hello there. I'm having the same problem as the above, but I'm using a 3D object (a cube to represent a mine-cart) and I want it to follow the train tracks path (drawn out using the iTween path system.
The problem is that the cart doesn't rotate (I think the rotation has to be on the Y axis for me since it's in 1st person view). Though I'm not sure how to go about coding that or setting it up. I read the answer above, I already had an empty game object, and the Z Axis (blue arrow) is pointing towards the "face/front" of the cart. It's still not working, and the cart doesn't rotate at all. It just moves along the path (in a funky unstable way if I may add).
Thanks.