Please point (ha!) me in the right direction with this...
I've been trying to add a script to an animated (flying) attachment I have, so that it always stays upright when I sit on a chair which causes my avatar's rotation to change (for instance lying down or inclined).
It's also important that the attachment remain facing the same way as my avatar is looking, in a horizontal plane I mean, at least mostly.
I've had partial success with the following code. I tried it by sitting on a cube and rotating it with the edit controls, while wearing the attachment. The attachment was continually adjusted to stay upright if I rotated the cube seat's x and y, but not z at the same time, or z alone but not x or y. If I tried rotating all together, the attachment just went to an odd angle. I'm guessing I need something like llRot2Up, but my brain started melting and my many experiments have failed. As has searching although surely I'm not the first to want to do this.
rotation avatar_rot;
vector avatar_vec;
default {
state_entry() {
llSetTimerEvent(0.5);
}
timer() {
avatar_rot=llGetRot();
avatar_vec=llRot2Euler(avatar_rot);
llSetRot(llEuler2Rot(<avatar_vec.x,avatar_vec.y,0>));
}
}
The code goes in the attachment's root prim. I can usually script quite well, but rotations just hurt.