Quaternion.Lerp problem [Excluding an Axis]

I have a waypoint driven camera system. The camera detects the closest waypoint, and copies the rotation gradually.

I’m trying to revise it so that it no longer rolls (movement on z-axis I believe) the camera when switching between waypoints, but I’m having issues with understanding how quaternions work…

Sir, it’s pssible this is what you’re looking for.

#pragma strict
var target:Transform;
function Update ()
var flatVersion:Quaternion;

flatVersion =

transform.rotation = Quaternion.Slerp(
        Time.deltaTime * .5);;

NOTE … for any beginners reading. Test by adding two cubes to a scene. Add the script to one cube. In the editor set ‘target’ to the other. Play, click on the ‘other’ cube, tap E on your Mac keyboard and spin the ‘other’ around using the natty circles.


#Thought of the day…

Try the following code instead. Do exactly what I mention above in the note for beginners to test it - click twice in the Editor to add two cubes and so on.

Note that this code below, in a sense, does the same thing you want… Notice it slerps the X and slerps the Y, and simply doesn’t bother with the z. Superficially it’s looking good.

Hit play and rotate the target cube GENTLY (SMALL AMOUNTS) in the editor. Try going only positive (watch the inspector) and then try going negative. Now try larger movements.

function Update ()
transform.eulerAngles.x = 

transform.eulerAngles.y = 

By playing with this you will discover all sorts of problems of this universe, such as gimbal lock! This is exactly why quaternions are used in this universe. Engineers, rocket aficionados, chemists and the like use quaternions everywhere - and the same is true in game engines. Quaternions make things unbelievably easy.

The facts that rotation in this universe is associative, and that rotation in this universe is not commutative, totally freaks me out. But that’s how it is.