   Orientation (Quaternion) from Vector
  Hi,I am trying to create steering behaviors in 3D.To make an agent able to rotate to look at a given point in space i use this method to calculate a new Orientation from the normalized lookAt vector.It works fine, except i would like the resulting orientation's up vector be as close to the world up as possible. This is were i am stuck :/Any help appreciated !private Quaternion GetOrientation(Vector3 targetOrientation){    Quaternion baseOrientation = Quaternion.Identity;    Vector3 baseZVector = Vector3.Forward;    if (baseZVector == targetOrientation)  return baseOrientation;    if (baseZVector == -targetOrientation)  return -baseOrientation;    Vector3 change = Vector3.Cross(baseZVector, targetOrientation);    float angle = (float)Math.Acos(Vector3.Dot(baseZVector, targetOrientation));    return Quaternion.CreateFromAxisAngle(Vector3.Normalize(change), angle);}Note: This code is based on an example from the book: "Artificial Intelligence for games". So i'm not sure my understanding of the math is correct.   
  There are a couple of problems with the code you posted, but if you want your agents to remain more or less upright as they move, you'll probably want to take a different approach anyway.First, I notice that you're computing the orientation 'from scratch', rather than using incremental rotations to align the agent towards the target. The 'from scratch' approach is a bit simpler to implement than the incremental version, but it doesn't always give the best results.In any case, what you want is an 'aim-at' transform. This is basically the same as the familiar 'look-at' transform, but is not inverted.The basis vectors for an 'aim-at' transform can be computed easily using cross products (if you're not familiar with the algorithm or need further details, feel free to ask). The only special cases to consider are when the agent position and the target position are coincident or nearly coincident, and when the agent is pointed more or less directly up or down (the algorithm may fail in these cases since there is no one unique orientation that satisfies the constraints).There isn't really a straightforward algorithm for building an 'aim-at' quaternion, so I would recommend building the orientation in matrix form, and then extracting the quaternion from the matrix (assuming you need the quaternion at all, that is - another option would be just to use matrices thoughout).   ;  Thanks for the help!This :Matrix lookAt = Matrix.CreateLookAt(Vector3.Zero, target, Vector3.Up);return Quaternion.CreateFromRotationMatrix(Matrix.Invert(lookAt));or more directlylookAt.Forward = target;lookAt.Right = Vector3.Cross(target, Vector3.Up);lookAt.Up = Vector3.Normalize(Vector3.Cross(lookAt.Right, target));lookAt.Right = Vector3.Cross(target, lookAt.Up);seems to work finehowever since i'm doing this right after:Quaternion newOrientation = GetOrientation(direction);Quaternion rotation = Quaternion.Inverse(self.Orientation) * newOrientation;float angle;output.Angular = MathExtra.QuaternionToAxisAngle(rotation, out angle) * angle;output.angle = angle;return output;Calculating the axis angle directly would be nicer, but i haven't been able to get it to work. Although i think it should be conceptually similar to creating the lookat matrix?   