- Home /
using itween to move objects in the 6 degrees of freedom
I am working on a school project where I have to give movement to an object. A friend of mine recommended that I use iTween. I started using it to move the object to the right but I want it to move the object right to left.
This is what I have so far:
public void MoveAcrossXPlane()
{
iTween.MoveTo(_cubeObject, Vector3.right, 0.5f);
}
Can anyone help me understand what I need to do? Thank you in advance!
Answer by GameVortex · Dec 17, 2013 at 02:43 PM
Vector3.right is just a shorthand for new Vector3(1, 0, 0). So you can supply your own vector for the left direction instead which is the negative direction of right: new Vector3(-1, 0, 0) or you can reverse the direction of the right Vector: -Vector3.right
A note on iTween: All the move functions uses a point in space to move towards and not a direction. The Vector3.right will move the object to that point (1, 0, 0), you can make it move further by multiplying the Vector with the distance you want it to go (-Vector3.right * distance). It will eventually stop though.
That answers why my cube is behaving that way, thank you. I also want it to loop right to left and vice-versa. Any idea on how to do that?
That is slightly more difficult because you have to start using iTweens hash methods because the normal $$anonymous$$oveTo only takes a few simple paramteters. The Hash works like this:
iTween$$anonymous$$oveTo(_cubeObject, iTween.Hash("position", position, "speed", speed, "looptype", iTween.LoopType.pingPong));
To move back and forth between two points we specify the "looptype" as PingPong. The first point is the point the gameobject is already on and the second point is the position variable supplied in the hash. We also supply a speed variable, or you can change it to "time" to move based on time ins$$anonymous$$d.
See the other options for the hash in the documentation: **ITween**
Your answer
![](https://koobas.hobune.stream/wayback/20220613124343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to control a game object's movement in iTween 1 Answer
how to loop an animation 2 Answers
How to reset an game object's position 1 Answer
RPC called by OnPhotonPlayerConnected doesn't work 2 Answers
Distribute terrain in zones 3 Answers