Copy rotation increments


Dear all,

I am trying to use maxScript to copy changes in the rotation of a node to another node (essentially recreating the Orientation constraint with the ‘Keep Initial Offset’ option on). So far I’ve come up with the code as follows

-- srcObj = source node from which rotation increments are copied
-- trgObj = receiving node
-- t0 = time from
-- t1 = time to

function copyRotIncrements srcObj trgObj t0 t1 =
	for t=t0 to t1 do
		animate on
			-- copying the change in the rotation of the source between t-1 and t
			rot = at time t srcObj.transform.rotation * (at time (t-1) inverse srcObj.transform.rotation)
			-- rotating the rotation matrix of the target, building up the transform matrix
			at time t trgObj.transform = translate ((rot * (at time (t-1) trgObj.transform.rotation)) as matrix3) trgObj.transform.pos

Somehow the script works correctly only if the source and the target have the same rotation initially. I’ve been trying to wrap my head around this for quite some time, but of no avail so far.

I would deeply appreciate any help and advice! Thank you very much for your consideration!