I was trying to make a camera look at a certain object. I used the following code:

diff = objs[2].location - objs[0].location
rot_quat = diff.to_track_quat('-Z','Y') 

Then, if I try to set the rotation using quaternion - it does not work.

camera.rotation_quaternion = rot_quat

But, when I try euler rotations - it works perfectly.

camera.rotation_euler = rot_quat.to_euler()

It seems weird to me that this should happen. Any ideas why this is?


It works with eulers because rotation_mode is set to XYZ by default.

Either change it to QUATERNION or modify matrix_basis (or some of the other matrix attributes). You can easily convert any quaternion to a matrix using its method to_matrix and resize it with to_4x4


mat = q.to_matrix().to_4x4()
mat.translation = cam.location
cam.matrix_basis = mat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.