- Home /
Use curve effect on rotation?
Hey all, I have a game where an object of mine with a rigidbody rotates into the ideal position for the direction it's facing. Here is the code:
float my_Aerodynamic = 0.2f;
my_Rigidbody.rotation = Quaternion.Slerp(my_Rigidbody.rotation, Quaternion.LookRotation(my_Rigidbody.velocity, transform.up), my_Aerodynamic*Time.deltaTime);
Slerp does not provide the desired transition. The object rotates at a constant speed toward the ideal rotation. I need a smooth transition that starts slow, speeds up over time, then slows down again. What can I use to get that curve transition effect?
Answer by taylank · Aug 27, 2016 at 04:29 AM
You can use Unity's own AnimationCurve class to define any sort of transition you want. https://docs.unity3d.com/ScriptReference/AnimationCurve.html
You can create a public AnimationCurve member on your MonoBehaviour and set the curve to desired shape in the editor. In the script, you can use the Evaluate function to figure out the desired rotation at a given time.