Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

There must be a better way to do this...

Maya Remblai
The one with pink hair.
Join date: 25 Mar 2006
Posts: 434
07-29-2006 19:05
This script does what it should - rotates a root prim back and forth, which is used to create a wagging flexiprim tail. The problem is it's the messiest script I've ever written! I know there must be a more effecient means of doing this, preferably one that doesn't require llResetScript everytime it runs. As it is, I can only use each set of rotations once, then the script has to be reset. Otherwise, the tail keeps on rotating, instead of rotating to the correct values.

CODE

vector original=<0,35,272>;
vector rotleft=<0,35,230>;
vector rotright=<0,35,290>;
vector rotleft2=<0,35,230>;
vector rotright2=<0,35,290>;
float time = 10;

SwishOne() {
rotleft *= DEG_TO_RAD;
rotation quat = llEuler2Rot(rotleft);
llSetRot(quat);
llSleep(.5);

rotright *= DEG_TO_RAD;
rotation quat2 = llEuler2Rot(rotright);
llSetRot(quat2);
llSleep(.5);
}

SwishTwo() {
rotleft2 *= DEG_TO_RAD;
rotation quat3 = llEuler2Rot(rotleft2);
llSetRot(quat3);
llSleep(.5);

rotright2 *= DEG_TO_RAD;
rotation quat4 = llEuler2Rot(rotright2);
llSetRot(quat4);
llSleep(.5);

}

OriginalPos() {
original *= DEG_TO_RAD;
rotation quat5 = llEuler2Rot(original);
llSetRot(quat5);
llSleep(.5);

}

default
{
state_entry()
{
llSetTimerEvent(time);
}

timer()
{
SwishOne();
SwishTwo();
OriginalPos();
llResetScript();
}
}

Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
07-29-2006 19:24
From: Maya Remblai
This script does what it should - rotates a root prim back and forth, which is used to create a wagging flexiprim tail. The problem is it's the messiest script I've ever written! I know there must be a more effecient means of doing this, preferably one that doesn't require llResetScript everytime it runs. As it is, I can only use each set of rotations once, then the script has to be reset. Otherwise, the tail keeps on rotating, instead of rotating to the correct values.


Look at your code. Notice that the code is repeated. Rewrite your code to eliminate the repetition. Once and once only. Hint:
CODE

rotright *= DEG_TO_RAD;
rotation quat2 = llEuler2Rot(rotright);
llSetRot(quat2);
llSleep(.5);
Maya Remblai
The one with pink hair.
Join date: 25 Mar 2006
Posts: 434
07-29-2006 21:04
I tried that Angela, it doesn't work. It won't let me use any of the (quat) values more than once. I repeated them so that I could get more than one tail swish out of each time the script runs.
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
Swish(); Swish(); Original();
07-29-2006 21:38
From: Maya Remblai
This script does what it should - rotates a root prim back and forth, which is used to create a wagging flexiprim tail. The problem is it's the messiest script I've ever written! I know there must be a more effecient means of doing this, preferably one that doesn't require llResetScript everytime it runs. As it is, I can only use each set of rotations once, then the script has to be reset. Otherwise, the tail keeps on rotating, instead of rotating to the correct values.
You are poisioning the well by adjusting degrees to radians EVERY time you use them, AND storing the result back into the same storage space. Either convert ONCE, or do NOT store the results back into the same place.

CODE

vector original=<0,35,272>; rotation quatorig;
vector rotleft=<0,35,230>; rotation quatleft;
vector rotright=<0,35,290>; rotation quatright;
float time = 10;

Swish() {
llSetRot(quatleft);
llSleep(.5);

llSetRot(quatright);
llSleep(.5);
}


OriginalPos() {
llSetRot(quatorig);
llSleep(.5);
}

default
{
state_entry()
{
quatleft = llEuler2Rot(rotleft * DEG_TO_RAD);
quatright = llEuler2Rot(rotright * DEG_TO_RAD);
quatorig = llEuler2Rot(original * DEG_TO_RAD);
llSetTimerEvent(time);
}

timer()
{
Swish();
Swish();
OriginalPos();
llResetScript();
}
}
Toodle-oo!
Maya Remblai
The one with pink hair.
Join date: 25 Mar 2006
Posts: 434
07-29-2006 23:58
Thank you Llauren! That's exactly what I needed! :)