Rotate Objects to Look at Pivot

I want to be able to run a script that runs on a selection of objects in which it rotates all the objects to make there X axis look at the pivot of a desired object.

Check out the images.
Image one is before the script is run.
Image two would be the result of what the script would do.

note: Not every case will have the objects displayed in a circular array.

Thanks

AttachmentSize
notmatching.jpg159.63 KB
rotatedtomatch.jpg158.06 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

A quick and dirty solution

A quick and dirty solution (read: resets scale as I feel quite lazy today) would be this:

fn rotateToTarget obj targetObj =
(
	obj.dir = normalize (targetObj.pos - obj.pos)
	local rotMatrix = (inverse (obj.rotation as matrix3))
	local newMatrix = obj.transform
		newMatrix.row1 = normalize rotMatrix.row3
		newMatrix.row2 = normalize rotMatrix.row1
		newMatrix.row3 = normalize rotMatrix.row2
	obj.transform = newMatrix
)
 
--for i in selection do rotateToTarget i $Sphere001

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.