I’m looking for a good solution for a situation I have where I am trying to rotate an object on the Y axis over time to face a player
Essentially what I have now is
Vector3 finalLookDir = new Vector3(0, Mathf.LerpAngle(ogEuler.y, lookDir.y, speed *Time.deltaTime), 0);
The issue with this is that when even when multiplying my Time.delta time the speed is not frame independent because, this is an exponential function.
I’m wondering if there is a linear function that is similar to lerp angle in that it wraps 180 to -180. I’ve been trying to write my own, but for some reason I’m having trouble conceptualizing it.
Also While I’m at it I’m having a similar issue at a different location in my code.
transform.rotation = Quaternion.Lerp(curRot, rotationTarget, Time.deltaTime * 8);
transform.rotation = Quaternion.RotateTowards(curRot, rotationTarget, Time.deltaTime * 100);
Both of these are also not frame rate independent.
All of these are being used in update of course.
thats a wrong way to lerp.
var timer = 0;
var duration = 1; // lerp duration
while(timer < duration){
Vector3 finalLookDir = new Vector3(0, Mathf.LerpAngle(ogEuler.y, lookDir.y, timer/duration), 0);
timer += Time.deltaTime;
yield return null;
}
Yes I know that, but this function needs to be in update because it’s constantly looking for the player.
Anyway someone else solved it. Quarternion rotate towards was that l what I was looking for.
Thanks for the help.