1
0

KanEd-Test16.lsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // This is a script designed to orbit its owner.
  2. vector startPos;
  3. vector curPos;
  4. vector offset; // offset from Agent
  5. integer iteration;
  6. float rotationRate; // degrees of rotation per iteration
  7. float sensorInterval; // seconds between sensor scan.
  8. default
  9. {
  10. state_entry()
  11. {
  12. llOwnerSay( "Hello, Avatar! Touch to start orbiting." );
  13. llSetStatus( 1, FALSE ); // turn Physics off.
  14. offset = < 2, 2, 1 >;
  15. iteration = 0;
  16. rotationRate = .5;
  17. sensorInterval = .3;
  18. }
  19. touch_start(integer total_number)
  20. {
  21. startPos = llGetPos();
  22. curPos = startPos;
  23. llSleep( .1 );
  24. key id = llGetOwner();
  25. llSensorRepeat( "", id, AGENT, 96, PI, sensorInterval );
  26. }
  27. sensor(integer total_number)
  28. {
  29. iteration++;
  30. if( iteration > 300 )
  31. {
  32. llResetScript();
  33. }
  34. if( llDetectedOwner( 0 ) == llGetOwner() )
  35. { // the detected Agent is my owner.
  36. vector position = llDetectedPos(0); // find Owner position.
  37. // calculate next object position relative both to the Owner's
  38. // position and the current time interval counter. That is,
  39. // use the iteration counter to define a rotation, multiply
  40. // the rotation by the constant offset to get a rotated offset
  41. // vector, and add that rotated offset to the current position
  42. // to defne the new position.
  43. float degreeRotation = llRound( rotationRate * iteration ) % 360;
  44. rotation Rotation =
  45. llEuler2Rot( < 0, 0, degreeRotation * DEG_TO_RAD > );
  46. vector rotatedOffset = offset * Rotation;
  47. position += rotatedOffset;
  48. // change the location of the object and save the current (rotated)
  49. // offset for use during the next iteration.
  50. llSetPos( position );
  51. offset = rotatedOffset;
  52. }
  53. }
  54. }