Search Unity

Help with interpolation

Discussion in 'Scripting' started by kiwi, Nov 28, 2010.

  1. kiwi

    kiwi

    Joined:
    Nov 13, 2008
    Posts:
    11
    Hey - I have an object that I rotate around its X and Y axis by using

    transform.Rotate(x,y,0.0F);

    which works fine. By doing this rotation the Transform also gets some z rotation which is also fine. What I want to though is then have the object's x and z axis return back to 0 while maintaining it's Y axis. So basically the tilt and roll come back to a neutral state while the yaw remains. If I run something like:

    transform.rotation=Quaternion.Lerp(transform.rotation,Quaternion.identity,Time.deltaTime);

    it (obviously) returns all three axis back to 0 - what's the best way for me set a target to interpolate to that'll keep the yaw?

    Any help appreciated.
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
  3. kiwi

    kiwi

    Joined:
    Nov 13, 2008
    Posts:
    11
    Thanks for the info. I ended up applying the rotation, storing the Y rotation, interpolating back to a neutral position and then re-applying the Y rotation. I'm not sure if it's the cleanest but it's only a few lines of code and seems to give a nice smooth result