I have a craft that turns (banks) left and right, and pitches up and down.
I need it to auto-level out when the user releases the key. Here is my code.
function FixedUpdate()
{
if (Input.GetKeyUp("a"))
{
startRot = transform.rotation;
ReturnRot (rotTime);
}
}
function ReturnRot (time : float)
{
var currentRot = this.transform.rotation * Quaternion.FromToRotation(transform.forward, Vector3.Scale(transform.forward, Vector3(1.0, 0.0, 1.0)));
var originalTime = time;
while (time > 0.0)
{
time -= Time.deltaTime;
transform.rotation = Quaternion.Slerp (startRot, currentRot, time / originalTime);
yield;
}
}
I get weird snapping and just unexpected results in game.
Basically I want to Slerp from the current rotation to the identity quat preserving the Y axis component.