aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/bin/assets/ScriptsAssetSet/KanEd-Test16.lsl
blob: 536ff19d2df469f298d0c4853ae8320ca8a41b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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; 
       }  
   }
}