Lerp doesn't work properly with eulerAngles nor rotation

Hi,
I want to rotate my object by 60 degrees, but when I use:

transform.eulerAngles = Vector3.Lerp(transform.eulerAngles,transform.eulerAngles + new Vector3(0,60,0), smooth * Time.deltaTime);

or :

transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.rotation.x,transform.rotation.y + 60,transform.rotation.z), smooth * Time.deltaTime);

None of them works and my object only rotates by about 7 degrees sometimes a little more sometimes a little less.
Thank you for helping

First, including all your script would be very helpful in answering this question. I see four (potential) issues here.

  • The code needs to be executed repeatedly in Update() or in a Coroutime with a ‘yield’ in order to make use of Lerp() for a gradual rotation. I’m guessing based on your symptom, you are only executing it once.
  • If you execute it over many frames, then you have the problem that you are setting your end rotation again each frame. That is, it is recalculating a new end rotation each time Lerp() is executed.
  • transform.rotation.* are not angles and cannot be treated as angles
  • For any given physical rotation, there are multiple euler angle representations, and Unity will change representation on you.

Take a look at this link. In particular, look at the EulerAngle section towards the end.

You might also examine the Rotation() function in this script:

http://wiki.unity3d.com/index.php?title=MoveObject

It uses a coroutine to execute a rotation over multiple frames.

You might also want to play with iTween…free in the Asset store.

You’re not using Lerp as it is intended, check this video:

If you jump to the minute 9:17, you have the exact code that you want.