1
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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

I.e.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .