I want to lerp a camera’s rotation FROM (35,0,0) TO (15,0,0) and have no idea how, because I haven’t gotten to Quaternions in math yet
I also tried
Camera.transform.rotation.x = MathF.Lerp(35,15,timeToLerp);
but it said I couldn’t do that, so I need to use
Camera.transform.rotation = Quaternion.Lerp(Camera.transform.rotation,???,timeToLerp);
I appreciate the help ^^
2 Answers
2
You don’t have to understand Quaternion math to use Quaternions. The class comes with many helper functions. While you can Slerp from one specific rotation to another, it is easier to Slerp from the current rotation to another specific rotation. If you first set the rotation. Here is a script:
#pragma strict
var speed = 55.0; // Degrees per second;
private var qFrom = Quaternion.Euler(35,0,0);
private var qTo = Quaternion.Euler(15,0,0);
function Start() {
transform.rotation = qFrom;
}
function Update() {
transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speed * Time.deltaTime);
}
First of all when you use Camera.transform.rotation as start value you actually don’t LERP anymore. It becomes a decellerated rotation. Your Mathf example does lerp because start and end value have to be constant for a linear interpolation.
To answer your ??? question:
Quaternion.Euler(15,0,0)
This creates a rotation out of the given eulerangles. Quaternions are better to represent rotations since they avoid a Gimbal lock
If you want to lerp between two rotation you have to store them both in a variable and use those to lerp. It depends on what you want.
The problem is that the assignment of the original rotation cannot be done at every frame. It needs to be done once at the start of the rotation. Take a careful look at my example code. I set the original rotation in Start(). Then you use RotateTowards() each frame with the current rotation as the first parameter.
– robertbu