Rotation problem [MaxScript]

I am trying to make a motion looper scirpt.
the script needs to get first frame and last frame position/rotation, average them and then assign the average value in both first and last frame of object animation.
the problem is that rotation will be different when I set it to first and last frame while exact same method works fine for position.
assume this:


AvRot = (quat 0.1, 0.1, 0.1, 0.2) //average value
at frame 0 animate on $.rotation = AvRot
at frame 100 animate on $.rotation = avRot

but the rotations will be different in frame 0 and 100.
I tried both euler and quat rotation for this but the results are similar.
how should I assign correct rotation to these frames?

It’s been a while since I’ve worked in maxscript, but a few questions come to mind;
[ol]
[li]Coordinate System? Local / world / etc?
[/li][li]Same RotationOrder?
[/li][li]And for keyframes u may want to consider using an animation controller » rotation.controller & rotation.controller.value
[/li][/ol]


-- Setting a node's rotation relative to world space without
-- messing with its position:
fn setNodeWorldRotation theNode theRot =
(
in coordsys (transmatrix theNode.transform.pos)
theNode.rotation = theRot
)

setNodeWorldRotation $ (eulerangles 45 45 0)

http://www.cgplusplus.com/online-reference/maxscript-reference/source/node_transform_properties.htm

Hope this helps

Thank you Proteoz.
I was tried coordinate systems (local/workd) but this coordinate system (transmatrix theNode.transform.pos) works.

theNode = $
at time 0 animate off theRot1 = theNode.rotation as quat
at time 100 animate off theRot2 = theNode.rotation as quat
theRot = slerp theRot1 theRot2 0.5

fn setNodeWorldRotation theNode theRot =
(
in coordsys (transmatrix theNode.transform.pos)
theNode.rotation = theRot
)

at time 0 animate on setNodeWorldRotation theNode theRot
at time 100 animate on setNodeWorldRotation theNode theRot

thank you very much :slight_smile: