LSL Status/Kan-ed16

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(New page: '''Code:''' // This is a script designed to orbit its owner. vector startPos; vector curPos; vector offset; // offset from Agent integer iteration; float rotationRate; ...)
 
Line 1: Line 1:
 
'''Code:'''
 
'''Code:'''
  
// This is a script designed to orbit its owner.
+
// This is a script designed to orbit its owner.
vector startPos;
+
vector startPos;
vector curPos;
+
vector curPos;
 
+
vector offset;            // offset from Agent
+
vector offset;            // offset from Agent
integer iteration;
+
integer iteration;
 
  float rotationRate;      // degrees of rotation per iteration
 
  float rotationRate;      // degrees of rotation per iteration
 
  float sensorInterval;    // seconds between sensor scan.
 
  float sensorInterval;    // seconds between sensor scan.

Revision as of 23:02, 16 December 2007

Code:

// This is a script designed to orbit its owner.
vector startPos;
vector curPos;

vector offset;             // offset from Agent
integer iteration;
float rotationRate;       // degrees of rotation per iteration
float sensorInterval;     // seconds between sensor scan.

default
{
   state_entry()
   {
       llOwnerSay( "Hello, Avatar! Touch to start orbiting." );
       llSetStatus( 1, FALSE );  // turn Physics off.
       offset = < 2, 2, 1 >;
       iteration = 0;
       rotationRate = .5;
       sensorInterval = .3;
   }

   touch_start(integer total_number)
   {
       startPos = llGetPos();
       curPos = startPos;
        
       llSleep( .1 );

       key id = llGetOwner();
       llSensorRepeat( "", id, AGENT, 96, PI, sensorInterval );
   }

   sensor(integer total_number)
   {
       iteration++;

       if( iteration > 300 )
       {
          llResetScript();
       }

       if( llDetectedOwner( 0 ) == llGetOwner() )  
       {        // the detected Agent is my owner.
          vector position = llDetectedPos(0);  // find Owner position.

          // calculate next object position relative both to the Owner's 
          // position and the current time interval counter.  That is, 
          // use the iteration counter to define a rotation, multiply 
          // the rotation by the constant offset to get a rotated offset 
          // vector, and add that rotated offset to the current position
          // to defne the new position. 
          
          float degreeRotation = llRound( rotationRate * iteration ) % 360;
          rotation Rotation = 
               llEuler2Rot( < 0, 0, degreeRotation * DEG_TO_RAD > );
          vector rotatedOffset = offset * Rotation;
          position += rotatedOffset;
          
          // change the location of the object and save the current (rotated) 
          // offset for use during the next iteration.
          llSetPos( position ); 
          offset = rotatedOffset; 
       }  
   }
}

Status: Does not run.

Personal tools
General
About This Wiki