Lerping Quaternion Eulers.
Is there anyway to Lerp/Slerp these values so that it takes time to reach them, and it isn't just instant. Vector3 dir = target.transform.position - turretBase.transform.position; Vector3 dir1 = target.transform.position - turretGun.transform.position;
Quaternion lookRot = Quaternion.LookRotation(dir);
Quaternion lookRot1 = Quaternion.LookRotation(dir1);
turretBase.transform.rotation = Quaternion.Euler(0, lookRot.eulerAngles.y, 0);
turretGun.transform.localRotation = Quaternion.Euler(lookRot1.eulerAngles.x, 0, 0);
Answer by doublemax · Nov 02, 2016 at 07:51 AM
You can use Quaternion.Lerp or Mathf.LerpAngle
https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html
https://docs.unity3d.com/ScriptReference/Mathf.LerpAngle.html
Yes but I don't understand how I could implement a lerp to my code so that it's a smooth and not instant transition.
This is usually done in a coroutine.
Here's a sample that moves one gameobject to a new position over time:
IEnumerator $$anonymous$$oveObjectToPosition( Transform trans, Vector3 end_position, float duration )
{
Vector3 start_position = trans.position;
float elapsed = 0.0f;
while( elapsed < duration )
{
trans.position = Vector3.Lerp(start_position, end_position, elapsed / duration );
elapsed += Time.deltaTime;
yield return null;
}
trans.position = end_position;
}
Alternatively i would recommend the "iTween" asset which is free and solves these kind of problems with a one-liner: https://www.assetstore.unity3d.com/en/#!/content/84
Another options is "LeanTween" which i have never used myself though. https://www.assetstore.unity3d.com/en/#!/content/3595
Your answer
Follow this Question
Related Questions
Look Rotation Viewing Vector is Zero 0 Answers
Maintaining look at target between two cameras 1 Answer
Rotate clockwise/counterclockwise using Quaternion.Slerp() 0 Answers
Rotational Velocity, Quaternions, Vector3 & Transfrom.rotation - Help 1 Answer
Quaternion.AngleAxis multiplied by vector gives wrong result 0 Answers