- Home /
help with returning object to original rotation
So i have an object that i want to rotate when the cursor is on screen but when i move the cursor off screen i want it to return to its original position. this is my code but it doesn't work.
var joint : GameObject;
var joint1 : Transform=joint.transform.rotation;
function Update () {
if mouse on screen do this.......
joint.transform.Rotate(Vector3(0,-1,0)*(Time.deltaTime));
if mouse not on screen....
joint.transform.rotation = Quaternion.Lerp(joint.transform.rotation, joint1, Time.deltaTime*100);
}
Thanks in advance
Answer by Waz · Aug 01, 2011 at 07:50 PM
joint1 should be private and a Quaternion not a Transform (and probably set in Start(), not like that).
Answer by intenzxboi · Aug 01, 2011 at 08:06 PM
Actually i figured it out.where stuff1 is ur current xyzw rotation coordinates and stuff2 i set as (0,0,0,0) for original.
in my case i used (0,0,joint.transform.rotation.y,0) for stuff1 cuz i only changed the y axis.
Hope this helps someone
var joint : GameObject;
function Update () {
if mouse on screen do this....... joint.transform.Rotate(Vector3(0,-1,0)*(Time.deltaTime));
if mouse not on screen.... joint.transform.rotation = Quaternion.Lerp(Quaternion(stuff1),Quaternion(stuff2), Time.deltaTime*100); }
Your answer
