- Home /
Simulating rotation-over-edge with iTween
Hello everyone,
I am very very new with Unity and I am trying to make a cube that moves like if it was rotated about one of its edges (simulating a torque). The best way I found so far to implement it perfectly was with iTween, but there is a problem. The first movement always runs perfectly, but in the following ones the cube rotates about a diferente axis. I know it has something to do with local and global coordinates systems, but i cant figure out how to solve it.
The cube has dimensions (1,1,1) and the Script to rotate it (almost) exactly by 1.0 in the z-direction is: (if I simply set up z= 1.0 it doesnt work, so I came up with this)
function Update () {
if (Input.GetKeyDown (KeyCode.UpArrow)){ iTween.moveAdd(gameObject, {"z":.78, "y":.78}); iTween.rotateTo(gameObject, {"x":90}); }
}
Anyone knows how to solve it?! Thanks a lot! =) P.S: I am using iTween 1.X (javaScript)
I fixed your tags; can you change "iTweet" to "iTween" in your question? Thanks.
Answer by pixelplacement · Sep 21, 2010 at 12:15 AM
Judging by the lower cased functions you are using with iTween ("moveAdd" and "rotateTo") it appeards you are using iTween 1.0.XX. I would STRONGLY recommend you upgrade to 2.0.XX if you can.
This example works for 2.0 and should work with 1.0 as well it allows for rotation in all directions with the arrow keys:
var moving : boolean; var time : float = .4; var easetype : String = "easeinoutsine"; var moveAmnt : float = 1; var rotAmnt : float = .25;
function Update () { if(Input.GetKey("up") && !moving){ moving=true; iTween.MoveTo(gameObject, {"z":transform.position.z+moveAmnt,"oncomplete":"resetMoving","easetype":easetype,"time":time}); iTween.RotateBy(gameObject, {"x":rotAmnt,"easetype":easetype,"time":time}); } if(Input.GetKey("down") && !moving){ moving=true; iTween.MoveTo(gameObject, {"z":transform.position.z-moveAmnt,"oncomplete":"resetMoving","easetype":easetype,"time":time}); iTween.RotateBy(gameObject, {"x":-rotAmnt,"easetype":easetype,"time":time}); } if(Input.GetKey("left") && !moving){ moving=true; iTween.MoveTo(gameObject, {"x":transform.position.x-moveAmnt,"oncomplete":"resetMoving","easetype":easetype,"time":time}); iTween.RotateBy(gameObject, {"z":rotAmnt,"easetype":easetype,"time":time}); } if(Input.GetKey("right") && !moving){ moving=true; iTween.MoveTo(gameObject, {"x":transform.position.x+moveAmnt,"oncomplete":"resetMoving","easetype":easetype,"time":time}); iTween.RotateBy(gameObject, {"z":-rotAmnt,"easetype":easetype,"time":time}); } }
function resetMoving(){ transform.eulerAngles=Vector3.zero; moving=false; }
Actually, I am very new in Unity, iTween and I have started to learn JavaScript to use in Unity3D but the new version of iTween is only in C# and I dont know how should I proceed. Do I need to write a script in C# in order to call iTween 2.0? Can I only use iTween 1.x if I want my scripts in JavaScript? If not, how should I proceed?!
Answer by pixelplacement · Sep 22, 2010 at 01:12 AM
You can use iTween 2.0 with JavaScript OR C#. Take a look at the Getting Started page to help you get going! Also, all of the examples are written in both JS and C# if you want to take a look at them.
Your answer

Follow this Question
Related Questions
Path Controlled Character and Working With Physics on iTween 1 Answer
iTween MoveUpdate Constant Speed? 2 Answers
Can I use iTween to change the parameters of a particles system over time? 1 Answer
iTween PutOnPath normalize percentage based on path length, not node-count? 1 Answer
ITween and Unity Postions. 1 Answer