Help With Simple Rotation

I’m struggling to get my head around this, but basically - I have a ResetRotation function in where I want it to:

yield WaitForSeconds(2);

and then reset the Y rotation to ‘0’ over time (so it looks like its animated).

How would one go about doing that?

Thanks

I added a second gif which covers the rest of the process to the README.md. http://i.imgur.com/02sruZr.gif You can see here the object getting logged when it becomes visible. This is clean project where I only added the 'AutomationHelpers.unitypackage' file before starting the capture. I hope this helps

4 Answers

4

it’s probably be better if u use the animation tab in unity, there a good basic tutorial on the unity site that shows u how to do it.
check here for the videos : http://unity3d.com/support/resources/tutorials/video-animation-view

or maybe what u can do is something like this

  transform.Rotate(Vector3.right * Time.deltaTime);

in this case it says its rotates the object on the x axes by 1 degree per sec, so not sure how to get exactly what u want myself but its a start.

If you could keep track of how far you are rotating as you are doing it, then you could just rotate the same amount again but negative.

Check documentation on how to use RotateTwoards. Or you can use

var reset : boolean; 
function Update(){
if(reset )
{
transform.Rotate(0,Mathf.Lerp(transform.rotation.y, 0,Time.time),0);
}
}

something like that would rotate it back to 0 on the y axis over 1 second whenever reset is true.

to activate it you could have reSet(); function reSet(){ reset = true; yield WaitForSeconds(1); reset = false; }

This does not work, any idea why?

Time.time starts counting at the start of the game, not at the start of this specific reset. In the reset function Anxo posted you could have var timer : float = Time.time and in the transform.Rotate replace Time.time with Time.time-timer

@Oliver Jones when you say "This does not work, any idea why? What do you mean? does it pop out an error? link the code you tried it with, mine was just an example to use as base you may not be able to copy and paste. please link the code you tried this with.

This is probably easiest done with a coroutine.

Typed in browser - may or may not compile :wink:

function ResetRotation(){
     var oldY : float = transform.eulerAngles.y;
     var t : float = 0.0;//animation time
     var speed : float = 1.0; //how fast you want the rotation to happen
     while(t < 1.0){ 
          transform.eulerAngles.y = Mathf.Lerp(oldY, 0.0, t); //rotate to the new position
          t += Time.deltaTime * speed;  //animate the time variable
          yield; //yield til the next frame
     }
}

Just call that function when you're ready to rotate back to 0, and it should handle the rest.