Quaternion.Lerp or Quaternion.RotateTowards? 9_BM_UTP

Hi guys,

Firstly, loving the course and eagerly look forwards to each new video. Having tried following along with a few YouTube tutorial series, which are very similar in structure and approach, I can say that the pacing and explanations given here set you guys above the rest.

My question is why are we using Lerp instead of RotateTowards in this instance?

 //Official solution
stateMachine.transform.rotation = Quaternion.Lerp(
                                                      stateMachine.transform.rotation, 
                                                      Quaternion.LookRotation(movement), 
                                                      stateMachine.LookRotateSmoothValue * deltaTime);

//Another approach
stateMachine.transform.rotation = Quaternion.RotateTowards(
                                                       stateMachine.transform.rotation,
                                                       Quaternion.LookRotation(movement), 
                                                       stateMachine.LookRotateSmoothValue * deltaTime); 

The other tutorials implied that RotateTowards was somehow better but never really explained how.

Is there a major difference or just a matter of preference?

Thanks for your help and these awesome videos!

Edit: For some reason it work accept the video unique tag in the tags field. 9_BM_UTP
Sorry if this has been defaulted to the wrong thread

https://answers.unity.com/questions/1557501/understanding-quaternionslerpquaternionrotatetowar.html

Not sure if I’m right in my understanding of LCStark’s answer in this but what I gather is:
Lerp will result in a faster turn speed the greater the rotation needed to be achieved
RotateTowards will result in a constant rotation speed regardless of the magnitude of rotation.

Obviously I cant be certain that I’m grasping that but in this instance what is our priority.

Do we want to complete a 90 degree turn in the same amount of time as a 180 degree turn or should it take twice as a long at a constant speed?

Not sure if its rude to answer my own topic but its here in case someone else has a similar question

1 Like

Hi @Alex_G1,

In which course and lecture are you?

Hi @Nina,

This is the Unity 3rd Person Combat & Traversal - EARLY ACCESS course

Lecture Movement Refactoring

We always encourage people to post potential solutions to their own questions as it leaves answers for others that may have the same question.

I grabbed Nathan on this one and this was his reply

“As far as I’m aware, both will achieve the same result (rotating over time) however they will do it with different curves. RotateTowards has a max degrees param so it will rotate at a fixed rate and immediately stop when at the correct rotation. Lerping with a speed * deltaTime on the other hand will rotate faster the further it is away from the desired rotation and will slow down as it gets closer, which will give a better/smoother look and feel to it”

Adding to my answer that Mark posted, it’s entirely preference of course. I personally prefer the Lerp rotation feel but use whichever method you prefer!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.