ScriptSpot

Forum topic · Scripts Wanted

Rotate Objects to Look at Pivot

By JokerMartini · 2011-01-14

Downloads
Description

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

Comments (1)

Swordslayer · 2011-03-08

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