Rotate pivot to Targeted Obj

How would I create this same script but without the hassle of using the point object and just modifying the actual objects pivot?

I'm trying to rotate a pivot to look in the direction of a target with an axis constraint.

To test just create a bunch of boxes on different position in 3d space and then create a sphere at 0,0,0 using that as the target.

targetObj = $Sphere001
sel = selection as array
for obj in sel do
(
	--pivotLookAt obj $Sphere001
	local dummyPt = point()
 
	dist = obj.pos - targetObj.pos
	dist = normalize dist
	upVec = [0,0,1]
	dp = dot dist upVec
	t = acos dp
	c = cross upVec dist
	c = normalize c	
	dummyPt.transform = obj.transform
	dummyPt.dir = c
	dummyPt.pos = obj.center
	in coordsys local rotate dummyPt (eulerangles -90 0 0)
	in coordsys local rotate dummyPt (eulerangles 0 0 -90)
 
	worldAlignPivot obj
	theRot = dummyPt.rotation
	in coordsys local obj.rotation *= theRot
	obj.objectoffsetrot*= theRot
	obj.objectoffsetpos*= theRot
	delete dummyPt
)

Comments

Comment viewing options

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

pseudoCode:pivot.angleAxisRo

pseudoCode:

pivot.angleAxisRotation axis:normalize(objectPoint3-pivotPoint3) angle:acos(dot (normalize (objectPoint3-pivotPoint3)) (normalize (PivotZVector)))

that should do it ;)

edit: "I'm Batman"

Raphael Steves

JokerMartini's picture

replacing variables

Would this be used in place of the PivotZVector Batman? PivotZVector = [0,0,1]
objectPoint3 = (object to which pivot will be pointed towards).position
pivotPoint3 = (currently selected object wishing to change).position

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Comment viewing options

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