2
$\begingroup$

I need to rotate the target object an equivalent distance to the distance between two objects in the direction of the travel distance between them.

enter image description here

I've tried to subtract them and get the rotation_difference between the subtraction result and a zero rotation axis mathutils.Quaternion() but the result is different from what I need.

import bpy
import mathutils

selected_object = bpy.context.object
car_f1_location = bpy.data.objects['car_f1'].location.copy()
car_f2_location = bpy.data.objects['car_f2'].location.copy()

direction_vec = car_f2_location - car_f1_location
direction = direction_vec.rotation_difference( mathutils.Quaternion() )

selected_object.rotation_quaternion = direction

But the resulting rotation is different from what I want.

$\endgroup$
  • $\begingroup$ Nice use of grease pencil in the screenshots :) $\endgroup$ – Moog Nov 5 '19 at 17:48
0
$\begingroup$

I figured out that I needed to use to_track_quat() instead of rotation_difference() to get the direction along this vector.

import bpy
import mathutils

selected_object = bpy.context.object
car_f1_location = bpy.data.objects['car_f1'].location.copy()
car_f2_location = bpy.data.objects['car_f2'].location.copy()

direction_vec = car_f2_location - car_f1_location
direction = direction_vec.to_track_quat('Y', 'Z')

selected_object.rotation_quaternion = direction
$\endgroup$

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.