# Help with llSetKeyframedMotion coordinate offsets

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

I have a little bit of code to make an object perform a loop. Movement isn't smooth yet, this is just a proof of concept while I experiment with this function call.

```deg45 =  llEuler2Rot(<0.0, -45.0, 0.0> * DEG_TO_RAD);

llSetKeyframedMotion( [
<0.5,.0,0.5>, deg45, 0.375,
<0.0,.0,0.5>, deg45, 0.375,
<-.5,.0,0.5>, deg45, 0.375,
<-.5,.0,0.0>, deg45, 0.375,
<-.5,.0,-.5>, deg45, 0.375,
<0.0,.0,-.5>, deg45, 0.375,
<0.5,.0,-.5>, deg45, 0.375,
<0.5,.0,0.0>, deg45, 0.375
], []);```

The rather big caveat about the position offsets using the global reference frame was buried at the very end of the wiki page. So of course I missed that at first and assumed the above code would function no matter what direction the "front" of the object was facing. Obviously, this is not the case. The above code is only valid for an object facing forward along the global X axis.

I thought I might be able to figure it out with some crude trig, but this doesn't work either. The object does not stay confiend to its "local" X axis as it goes through the move.

```deg45 = llEuler2Rot(<0.0, -45.0, 0.0> * DEG_TO_RAD);vector r = RAD_TO_DEG * llRot2Euler(llGetRot());
float sin = llSin(r.z);
float cos = llCos(r.z);

llSetKeyframedMotion( [
<0.5*cos,  0.5*sin,  0.5>, deg45, 0.375,
<0.0,      0.0,      0.5>, deg45, 0.375,
<-.5*cos,  -.5*sin,  0.5>, deg45, 0.375,
<-.5*cos,  -.5*sin,  0.0>, deg45, 0.375,
<-.5*cos,  -.5*sin,  -.5>, deg45, 0.375,
<0.0,      0.0,      -.5>, deg45, 0.375,
<0.5*cos,  0.5*sin,  -.5>, deg45, 0.375,
<0.5*cos,  0.5*sin,  0.0>, deg45, 0.375
], []);```

So how would I go about converting the above offsets to work for any rotation that the object might be set at. We can assume the the object will always be level with the horizon, so only the rotation about the z axis will be relevant. I appreciate any help!

##### Share on other sites

I'm not sure I entirely understand what you're doing, but maybe this is closer:

`list rawOffsets =    [ <0.5,.0,0.5>    , <0.0,.0,0.5>    , <-.5,.0,0.5>    , <-.5,.0,0.0>    , <-.5,.0,-.5>    , <0.0,.0,-.5>    , <0.5,.0,-.5>    , <0.5,.0,0.0>    ];default{    touch_start(integer total_number)    {        list kfmList;        integer offsetIdx;        integer offsetCount = llGetListLength(rawOffsets);        while (offsetIdx < offsetCount)        {            kfmList += llList2Vector(rawOffsets, offsetIdx++) * llGetRot();            kfmList += 0.375;        }        llSetKeyframedMotion(kfmList, [KFM_DATA, KFM_TRANSLATION]);    }}`

##### Share on other sites

Ah! That's it exactly. Sheesh... all I had to do was multiply the offset by the global rotation?

I was making it harder than it needed to be. Thanks Qie!