User:Toady Nakamura/Touch Toggle Rotate

From Second Life Wiki
Jump to navigation Jump to search

Make a cylinder that looks like a record or a CD.

Place this script inside...

integer spinning = FALSE;
default
{
    touch_start(integer total_number)
    {
        if(!spinning)  // if not presently spinning
        {
            llTargetOmega(<0.0, 0.0, 1.0>, -PI_BY_TWO, -0.01); //start spinning
            spinning = TRUE; // remember that spinning is now true
        }
        else  // if presently spinning
        {
            llTargetOmega(ZERO_VECTOR, 0, 0);  // stop spin
            spinning = FALSE; // remember that spinning is now false
        }
    }
}


How llTargetOmega works...

  • for the function that reads: llTargetOmega(<0.0, 1.0, 0.0>, TWO_PI, 1);
  • The first parameter is axis of rotation expressed as a vector (<0,1,0>) which will rotate the prim on the Y axis
  • To change the axis to x <1,0,0>... to change it to z <0,0,1> and to reverse direction <-1,0,0>, <0,-1,0>, <0,0,-1>

The second parameter is the rate of rotation in radians per second.

  • PI_BY_TWO (slow counterclockwise), -PI_BY_TWO (slow clockwise)
  • PI (counterclockwise) or -PI (clockwise)
  • TWO_PI (counterclockwise) or -TWO_PI (clockwise)

The third parameter is the gain. (should not equal zero - subtle effect)


script written 02-22-08 inspired by Torley's record player--Toady Nakamura 11:40, 14 May 2012 (PDT)

Another way to do the same thing

After this page was posted, a fancier scriptor came along and changed it, completely losing the notes to help new learners and making it where it no longer matches the inworld teaching notes. I am adding their version to the bottom of the page, so they won't feel left out. Yes, it is probably "better" but no it doesn't match the notes, nor show the concepts pointed out in the class as we streamline the scripts together.

integer spinning;// = FALSE;
 
default
{
    touch_start(integer num_detected)
    {
    //  toggle between TRUE (1) and FALSE (0)
        spinning = !spinning;
 
        if (spinning)// is on turn it off
            llTargetOmega(ZERO_VECTOR, (float)FALSE, (float)FALSE);
 
        else// turn it back on
            llTargetOmega(<0.0, 0.0, 1.0>, -PI_BY_TWO, -0.01);
    }
}

While this is a more academically "perfect" script, without inline notes it makes utterly no sense to a beginning learner.

Visit my LSL wiki page for my library of simple scripts ! Toady Nakamura