Jump to content

Animate Texture 30 Degree Back And Forth


IZHRAH
 Share

You are about to reply to a thread that has been inactive for 3259 days.

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

Recommended Posts

Hi if there a way that I can rotate the texture 30 degree back and forth using the animate texture? it seems the rotate texture is not applicable to this situation because its not animating actually.

AnimTexture.jpg

Link to comment
Share on other sites

Try this...

// Texture Waverinteger direction = 2; // flag for keeping track of rotation direction, 2/-2float time = 2.0; // time for one cycleinteger resetCount = 10; // number of cycles before position reset (to account for lag)integer resetTimer = 0;integer Faces = ALL_SIDES;float Angle;default {    state_entry() {        llSetTimerEvent(time/2);        Angle = TWO_PI/24; // 30 Degrees    }    timer(){       if(resetTimer>0){            resetTimer--;        }        else{ // TWO_PI/24 is 30 degrees, TWO_PI/12 is 60 degrees            llSetTextureAnim(0       | SMOOTH | ROTATE | LOOP, Faces,1,1,-Angle, TWO_PI, direction*Angle); // Turn off animation, which also resets orientation            llSleep(0.1); // we seem to need a little sleep  to allow the texture animation to turn off/reset            llSetTextureAnim(0       | SMOOTH | ROTATE | LOOP, Faces,1,1,-Angle, TWO_PI, direction*Angle); // Do it again for reliability            resetTimer = resetCount*2-1;            direction = 2;        }        if(direction == 2){            llSetTextureAnim(ANIM_ON | SMOOTH | ROTATE | LOOP, Faces,1,1,-Angle, TWO_PI, direction*Angle);            direction = -2;        }        else {            llSetTextureAnim(ANIM_ON | SMOOTH | ROTATE | LOOP, Faces,1,1,-Angle, TWO_PI, direction*Angle);            direction = 2;        }    }}

I've used llSetTextureAnim() to rotate the texture, first in one direction, then in the other. Each rotation is "direction" (which is either +2 or -2) times your requested angle of 30 degrees. The rotation starts at -30 degrees, so the wave is centered around zero. Because texture rotations are viewer side, they can become decoupled from the prim's server side orientation. For that reason, every "resetCount" cycles of the wave, the texture animation is turned off. This resets the texture to its normal position on the prim, just in case it has drifted.

 

Turning off animation doesn't always seem to work, and it doesn't seem to work if there isn't a small llSleep() after the function. And it seems to work better if there's yet another call to turn off animation. Don't ask me to explain why I needed those things, I just noodle until things work and then run away.

If you don't want to animate all the faces, change Faces to the correct value.

Good luck, have fun!

Link to comment
Share on other sites

One beauty of llSetTextureAnim(() is that, for a given setting, it becomes a prim property and henceforth the script doesn't have to do anything -- and can even be removed -- as long as the same animation is to continue. That's not only a win for the sim (not having to run the script) but also the network and viewer (no object updates).

In this case, the direction of rotation cycles back and forth -- but luckily, the function has a PING_PONG parameter.

So this might suffice:

// Texture Waverfloat CYCLES_PER_SECOND = 0.5;integer FACES = ALL_SIDES;  // Change if you want just one facefloat ANGLE_DEGREES = 30.0;default {    state_entry()     {        float angleRadians = ANGLE_DEGREES * DEG_TO_RAD;        llSetTextureAnim            ( ANIM_ON | SMOOTH | ROTATE | LOOP | PING_PONG  // PING_PONG reverses direction each cycle            , FACES            , 1, 1      // (These parameters ignored for ROTATE animation)            , -angleRadians    // Start angle in radians            , angleRadians * 2.0   // Length of animation in radians            , CYCLES_PER_SECOND            );    }}

 

  • Thanks 1
Link to comment
Share on other sites

I'll have to try PING_PONG again, Qie. My script is very old, but I recall having to re-anchor the animation now and then because it drifted. I recall being baffled by that at the time because the animation is entirely client side, though at that time I also witnessed glitches in smooth scrolling that caused animations on different prims to go out of sync.

ETA: I've been watching/camming around/switching apps for a few minutes and it's looking good. I suspect you had no doubt.

;-).

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3259 days.

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...